Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
430 views
in Technique[技术] by (71.8m points)

swift - Parsing GPX File - Elevation Values

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...