Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

specify the name of country using longitude and latitude on android

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.

like image 763
Adly Avatar asked Mar 30 '12 18:03

Adly


People also ask

How do I set latitude and longitude on Android?

Select Location > Then set the Latitude and Longitude values. Then press Send to set the Latitude and Longitude values to the emulator device.

How do you write your location using latitude and longitude?

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."

How can I find the location of a country name?

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.


1 Answers

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
    }

}
like image 95
Cristian Avatar answered Sep 30 '22 18:09

Cristian