3

We’re developing an iOS app. One requirement we have is, get the country of the user location to enforce restrictions in the app. One solution we’re thinking about is to gather the IP address and use it with a Geo-localization service to get the country. One partner told us that this kind of solution violates Apple policies. Could someone confirm this statement? Or, someone knows another way to gather just the country where the device user is located?

pnuts
  • 58,317
  • 11
  • 87
  • 139
shinjidev
  • 383
  • 1
  • 6
  • 21

4 Answers4

10

Use the Apple-provided location services to find the location of the user. It's by far more accurate than geocoding from IP addresses, it doesn't require a third party service (or your own service) and it provides an estimated Latitude and Longitude for the user that you can use on a map or similar.

Nick
  • 9,792
  • 7
  • 50
  • 60
  • I understand, but we were trying to do something like Pandora or Netflix, because we think they aren't using latitude and longitude to enforce restrictions. – shinjidev Mar 08 '12 at 20:02
  • Pandora and Netflix are most likely handling any restrictions using "internationalization"... https://developer.apple.com/library/ios/#documentation/MacOSX/Conceptual/BPInternational/BPInternational.html – Tonetel Mar 08 '12 at 20:52
  • Well, i'm not talking about restrictions in the language, i'm trying to restrict the service for some countries, that is why i need to know the country's user – shinjidev Mar 08 '12 at 21:46
  • @shinjidev those are your choices. I think a key question is this: do you want users in an allowed country to be able to use the app when they travel to a non-allowed country? – Nick Mar 08 '12 at 22:07
  • No, according with the policies in the enterprise they shouldn't be able to use the app, that's why we tried to use the ip address. – shinjidev Mar 08 '12 at 22:10
2

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

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

atrljoe
  • 8,031
  • 11
  • 67
  • 110
  • I understand, but we were trying to do something like Pandora or Netflix, because we think they aren't using latitude and longitude to enforce restrictions. – shinjidev Mar 08 '12 at 20:10
2

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

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

Hubert Kunnemeyer
  • 2,261
  • 1
  • 15
  • 14
0

You could use Google Reverse Geocoding API to get the country named based on the user location coordinates

ale84
  • 1,406
  • 12
  • 16