Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get country from coordinates?

Tags:

How to get country name in Android, If are known geo coordinates? How to make it the simplest way?

like image 303
ArtKorchagin Avatar asked Jun 18 '12 12:06

ArtKorchagin


People also ask

How do I find a location using latitude and longitude?

To find a location using its latitude and longitude on any device, just open Google Maps. On your phone or tablet, start the Google Maps app. On a computer, go to Google Maps in a browser. Then enter the latitude and longitude values in the search field — the same one you would ordinarily use to enter an address.

How do I find the geocode of a location?

One way to find your geolocation is to simply perform a lookup online. Melissa's Geocoder Lookup tool returns latitude, longitude, county, census tract and block data based on an address or ZIP Code. Simply enter the address or ZIP Code into the easy-to-use Lookups interface and submit.


2 Answers

Here you go

Geocoder gcd = new Geocoder(context, Locale.getDefault()); List<Address> addresses = gcd.getFromLocation(lat, lng, 1);      if (addresses.size() > 0)      {          String countryName=addresses.get(0).getCountryName();      } 
like image 86
Vipul Avatar answered Sep 24 '22 19:09

Vipul


Use Below Function for that.

public void getAddress(double lat, double lng) {     Geocoder geocoder = new Geocoder(HomeActivity.mContext, Locale.getDefault());     try {         List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);         Address obj = addresses.get(0);         String add = obj.getAddressLine(0);         GUIStatics.currentAddress = obj.getSubAdminArea() + ","                 + obj.getAdminArea();         GUIStatics.latitude = obj.getLatitude();         GUIStatics.longitude = obj.getLongitude();         GUIStatics.currentCity= obj.getSubAdminArea();         GUIStatics.currentState= obj.getAdminArea();         add = add + "\n" + obj.getCountryName();         add = add + "\n" + obj.getCountryCode();         add = add + "\n" + obj.getAdminArea();         add = add + "\n" + obj.getPostalCode();         add = add + "\n" + obj.getSubAdminArea();         add = add + "\n" + obj.getLocality();         add = add + "\n" + obj.getSubThoroughfare();          Log.v("IGA", "Address" + add);         // Toast.makeText(this, "Address=>" + add,         // Toast.LENGTH_SHORT).show();          // TennisAppActivity.showDialog(add);     } catch (IOException e) {         // TODO Auto-generated catch block         e.printStackTrace();         Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();     } } 

Add Below Permission to your manifest

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
like image 35
Dipak Keshariya Avatar answered Sep 20 '22 19:09

Dipak Keshariya