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.
Select Location > Then set the Latitude and Longitude values. Then press Send to set the Latitude and Longitude values to the emulator device.
For example, a location could be found along the latitude line 15°N and the longitude line 30°E. When writing latitude and longitude, write latitude first, followed by a comma, and then longitude. For example, the above lines of latitude and longitude would be written as "15°N, 30°E."
Just pass your lat-long in address. And look for "long_name" which have "country,political" in "types" array. Show activity on this post. From a Geocoder object, you can call the getFromLocation(double, double, int) method.
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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With