1

I'm actually using the maps' API for an android application and I need to get an adresse from 2 coords. So, someone have an idea how can I convert Lat, Lng into an adresse ? If it's not possible to get an adresse, is it possible to get a place near this point ?

Thank's in advance!

Belved
  • 55
  • 8
  • Please go through the below link, https://stackoverflow.com/questions/27244763/how-to-get-address-from-latitude-and-longitude-in-android https://stackoverflow.com/questions/9409195/how-to-get-complete-address-from-latitude-and-longitude Ankit – Ankit Dubey May 13 '18 at 01:21
  • Use [Google Reverse Geocoder](https://developers.google.com/maps/documentation/geocoding/intro#ReverseGeocoding), as far as I know it's more accurate – Suleyman May 13 '18 at 03:46

1 Answers1

1

Use geocoder.

Geocoder geocoder;
List<Address> yourAddresses;
geocoder = new Geocoder(this, Locale.getDefault());
yourAddresses= geocoder.getFromLocation(yourLatitude, yourLongitude, 1);

if (yourAddress.size() > 0)
{
 String yourAddress = yourAddresses.get(0).getAddressLine(0);
 String yourCity = yourAddresses.get(0).getAddressLine(1);
 String yourCountry = yourAddresses.get(0).getAddressLine(2);
}
  • I got an "unhandled exception: Java.io.IOException" for this line : getFromLocation(yourLatitude, yourLongitude, 1); I didn't found anything on the net to solve it... Any idea ? – Belved May 13 '18 at 13:58
  • I just needed to catch the IOException... I definitively need to sleep... By the way, it works well, thank's for your help. Just be careful, yourCity and yourCountry can be null – Belved May 14 '18 at 07:51