I'm trying to get the elevation values from a GPX file and add them to an array so I can do some calculations for total elevation gain for a route.
I have managed to get the coordinates and append them to a dictionary array and display the route on a map, however, I can't seem to get the "ele" value.
The following is the code I use to retrieve coordinates (parsing the GPX file):
func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String]) {
if elementName == "trkpt" || elementName == "wpt" {
let lat = Double(attributeDict["lat"]!)
let lon = Double(attributeDict["lon"]!)
let coordinateData = CLLocationCoordinate2D(latitude: lat!, longitude: lon!)
coordinates.append(coordinateData)
}
}
This is part of the detail in the GPX file and I am interested in the "ele" value. What's the best way to do this?
<trkpt lat="51.47777000000001" lon="-0.9179800000000001">
<ele>35.85</ele>
</trkpt>
<trkpt lat="51.47795000000001" lon="-0.9184300000000001">
<ele>35.85</ele>
</trkpt>
<trkpt lat="51.47820500226592" lon="-0.9191599959184358">
<ele>35.870000000000005</ele>
</trkpt>
question from:
https://stackoverflow.com/questions/66054744/parsing-gpx-file-elevation-values 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…