Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Getting: Unable to geocode zipcode (Geocoder services are not available)
- using this link, provided by YOU: http://stackoverflow.com/questions/3641304/get-latitude-and-longitude-using-zipcode
- PERMISSION DEFINED IN MANIFEST:
- <uses-permission android:name="android.permission.INTERNET"/>
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
- <uses-permission android:name="android.permission.ACCESS_GPS" />
- btnSearchByPostalCode.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- // strPostalCode = editPostalCode.getText().toString();
- strPostalCode = "90012";
- try {
- geocoder = new Geocoder(getBaseContext(), Locale.getDefault());
- List<Address> addresses = geocoder.getFromLocationName(strPostalCode, 1);
- if (addresses != null && !addresses.isEmpty()) {
- Address address = addresses.get(0);
- // Use the address as needed
- String message = String.format("Latitude: %f, Longitude: %f",
- address.getLatitude(), address.getLongitude());
- Toast.makeText(LocationsActivity.this, message, Toast.LENGTH_LONG).show();
- } else {
- // Display appropriate message when Geocoder services are not available
- Toast.makeText(LocationsActivity.this, "Unable to geocode zipcode", Toast.LENGTH_LONG).show();
- }
- } catch (IOException e) {
- // handle exception
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement