so in my other question I asked, I found out that I can create easily gpx files, but now I need to display the content of the gpx file as a MKPolygon. Before, I had created the list with all the coordinates in a plist file, this was easy to read since I could just make a NSDictionary and read it from there and finding the location using the keys that a plist supplies, however it doesn't seem to work this easy in a gpx file.
I've created this little snipped of code to read the whole content of the gpx file:
if fileManager.fileExistsAtPath(filePath) {
let dataBuffer = NSData(contentsOfFile: filePath)
let dataString = NSString(data: dataBuffer!, encoding: NSUTF8StringEncoding)
print (dataString)
}
So now I have the whole text in a string but I don't need all this:
<?xml version="1.0" encoding="UTF-8"?>
<trk>
<name>test</name>
<desc>Length: 1.339 km (0.832 mi)</desc>
<trkseg>
<trkpt lat="-39.2505337" lon="-71.8418312"></trkpt>
<trkpt lat="-39.2507414" lon="-71.8420136"></trkpt>
</trkseg>
</trk>
</gpx>
I just need the latitudes and longitudes between the <trkpt>
tags so I can convert them into locations and from there convert it into a MKPolygon.
Any help would be greatly appreciated as I haven't found anything in google on how to read gpx files with swift.
Thanks in advance -Jorge