SaltyNuts
SaltyNuts

Reputation: 5168

Determine the country by latitude/longitude coordinates in iOS MapKit

I'm using MapKit to display a map with matching data points to a user. One of the filters in the search is the country (in South America, not that it matters too much). Aside from letting the user select the country by name from a list, I would like them to be able to tap the map in the desired location. The trick is to translate the lat/lon coordinates of the touch to a country. I don't suppose there is any way to do that in iOS?

I wanted to get the countries' coordinates as GPS polygons (http://www.gadm.org/country has a great free database) but the detailed files from GADM are a little too detailed for my needs. The KML file for Brazil, for example, is over half a million GPS points, with over 800 separate polygons. Is there a tool that can be fed these files and intelligently simplify them to a more manageable number of points?

Upvotes: 1

Views: 1033

Answers (1)

Duncan C
Duncan C

Reputation: 131471

You can do this quite easily with reverse geocoding. The class you want is CLGeocoder. You'll get back a CLPlacemark if the operation is successful. The CLPlacemark has both a country field (a string with the name of the country in language of the current locale) and an ISOcountryCode.

If you wanted to do this yourself you'd need a file with country boundaries and a GIS package. However, country boundaries are complex, so those files will be pretty big. If you want accuracy at the border you need lots of detail.

Upvotes: 1

Related Questions