Skip to content Skip to sidebar Skip to footer

Getting Address Of A Location From Latitude And Longitude In Android

I am building an application. In which now i am getting the map and also the latitude and longitude of the touched location. I also wanted the address of the touched location corre

Solution 1:

To get the address from the lat, long,

Try this code,

Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);

EDIT:

   String addressString;

try {
  Geocoder geocoder = new Geocoder(this, Locale.getDefault());
  List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
  StringBuilder sb = new StringBuilder();
  if (addresses.size() > 0) {
    Address address = addresses.get(0);

    sb.append(address.getLocality()).append("\n");
    sb.append(address.getCountryName());
  }

  addressString = sb.toString();

  Log.e("Address from lat,long ;", addressString);
 } catch (IOException e) {}
}

For exception :

java.io.IOException: Service not Available
at android.location.Geocoder.getFromLocation(Geocoder.java:117)

It's a bug in the emulator for 2.2 http://code.google.com/p/android/issues/detail?id=8816

also here: http://groups.google.com/group/android-developers/browse_thread/thread/b02c29d746471358


Post a Comment for "Getting Address Of A Location From Latitude And Longitude In Android"