I have a KML file with all the countries and polygons. I am trying to create an app that get a Lat & Lon and detecting in which country belongs using this KML. I tried SimpleKML and KMLViewer with no luck.
The kml structure is:
<Document>
<Folder>
<Folder>
<name>A -</name>
<Placemark>
<name>Afghanistan</name>
<description></description>
<Style>
<PolyStyle>
<color>aaffffff</color>
<colorMode>random</colorMode>
</PolyStyle>
</Style>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
65.62729644775391,37.33319854736328,0 65.64692687988283,37.45888137817383,0
...
...
coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
<Placemark>
<name>Albania</name>
..
..
..
1) It would be better to use xml parser and save the data on a local database?
2)Is there any function to determine in which polygonal is the given lat/lon ?
Thank you
The parsing should be pretty easy using NSXMLParser, look for names and associate them with coordinates. The more interesting part is to test the polygons for inclusion of a point.
Here’s a highly regarded SO article, that looks like it borrows somewhat from this wikipedia article. What you would do is build a collection of polygons, and enumerate them testing each for the inclusion of some given coordinates.
The other thing to think about is to skip the parsing and polygon testing altogether and use the google geocoding api. This section talks specifically about getting address info (including country) from a latitude and longitude.