I have two questions. In my app, I am getting the GPS coordinates of friends. How can I determine if those friends are in the US/Canada?
The second question is to find out开发者_开发技巧 if the actual device is in the US/Canada?
The term for this is Reverse Geocoding. You want to have a look at the MKReverseGeocoder class and its sample code, this is Apple's solution for this. However, it requires you to display a map (which may or may not be what you want).
If you don't want the map then things get a little bit more complicated. See Offline Reverse Geocoding at Country Level and Techniques for offline reverse geocoding on a mobile device?.
You can use the Reverse Geocoding API of google to get the address corresponding to the coordinates and extract the country details from the response's address_components.
http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true
精彩评论