How to get country name in Android, If are known geo coordinates? How to make it the simplest way?
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.
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.
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(); }
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"/>
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