Reputation: 597
I'm using google api 15 on android emulator.
I want to specify a country from a map by using a touch to the screen, So if I made a touch to the screen on some longitude and latitude, I can know to what country or a city those belong to?
.. Thanks a lot.
Upvotes: 5
Views: 8354
Reputation: 200140
You can try something like this:
public static String getCountryName(Context context, double latitude, double longitude) {
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
List<Address> addresses = null;
try {
addresses = geocoder.getFromLocation(latitude, longitude, 1);
Address result;
if (addresses != null && !addresses.isEmpty()) {
return addresses.get(0).getCountryName();
}
return null;
} catch (IOException ignored) {
//do something
}
}
Upvotes: 21