IOS Get the country the device user is in

Developed an iOS application. One of the requirements we have is to force the user's location country to enforce restrictions in the app. One solution was to collect the IP address and use it with a geolocation service to get the country. One of the partners told us that such a decision violates Apple's rules. Can anyone confirm this expression? Or does someone know another way to collect only the country where the device user is located?

+3


source to share


4 answers


Use Apple-provided location services to find a user's location. It is much more accurate than geocoding from IP addresses, it does not require a third party service (or your own service), and it provides an approximate latitude and longitude for the user that you can use on a map or similar.



+10


source


Using location services provided by Apple is only part of the solution. Since location services do not return a country, you will need to use a service that accepts latitude and longitude to determine nearby countries. I've used this before for other purposes, but a request for something like this web service with latitude and longitude should return you a country nearby.



http://ws.geonames.org/findNearby?lat=47.3&lng=9

+2


source


Apple has a reverse Geocoder API now CLGeocoder. It converts longitude and latitude into a user-friendly representation. I would use location services and CLGeocoder to get this information, so you won't have any problems later and you don't need third party APIs.

https://developer.apple.com/library/ios/#DOCUMENTATION/CoreLocation/Reference/CLGeocoder_class/Reference/Reference.html#//apple_ref/occ/cl/CLGeocoder

+2


source


You can use the Google Reverse Geocoding API to get the country name based on the coordinates of the user's location

0


source







All Articles