How to find the address of a place in an android app [closed]
开发者_开发技巧
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this questionIn my app I want to show the latitude, longitude and address of a location. I am able to find an API for latitude and longitude, but is there any API to find the address of a place corresponding to the latitude and longitude.
you can use Geocoder to return addresses from lat/lon like this.
Geocoder geocoder = new Geocoder(this, Locale.US);
double lat = 41.146064;
double lon = 80.642861;
try{
List<Address> loc = geocoder.getFromLocationName(lat, lon, 5);
}
catch(IOException e) {
Log.e("IOException", e.getMessage());
Toast.makeText(this, "IOException: " + e.getMessage(),20).show();
}
//DO something with loc
You should know that Geocoder will not always return with a result, it may take a few tries thats why it's wrapped with a try catch. This way you can write to Toast or Logcat with the IO exception msg.
Also you will get the best results when you pass it a locale in the Geocoder constructor as I am doing.
See Geocoder.getFromLocation
精彩评论