0

I'm trying to use a Phone's Location Services to acquire it's current Country. I've searched over the internet and many cases taught how to get the Long. and Lat. of a phone, but not the country.

To be clear, I'm not trying to get the Phone's Country using:

String locale = this.getResources().getConfiguration().locale.getDisplayCountry();
  • I'm not looking for an exact address (City, Street etc.), just the Country.
  • I don't need the SIM Card's country (Ex: French user travels to Spain will return France and not Spain)

I've used LocationManager but have no idea how to get Location information from it.

Villager
  • 89
  • 2
  • 2
  • 9

2 Answers2

0

Use the Geocoder getFromLocation which returns and Address which has the Country in it

tyczj
  • 71,600
  • 54
  • 194
  • 296
0

You can use Google's geocoder api to get the full address and then simply extract the country name from it. It's super easy! https://developer.android.com/reference/android/location/Geocoder.html . This might be overkill for what you want but it certainly does the job

  • Lets say I don't have the Lang and Lat, but I do have permission to use the phone's location services. Is there a way to "extract" the country based on that permission? Or must I get the Lang & Lat for that? – Villager Feb 07 '18 at 17:19
  • It's really easy to get lat long of device anyway, so you should get lat long and then use the geocoder API. To get lat/long: use LocationManager and then just use the .getLastKnownLocation() method of the location manager. Here is a good resource on using the LocationManager easily: https://stackoverflow.com/questions/20210565/android-location-manager-get-gps-location-if-no-gps-then-get-to-network-provid – Shane Monks O'Byrne Feb 07 '18 at 17:50