/
ViewController.swift
58 lines (43 loc) · 1.86 KB
/
ViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// ViewController.swift
// GPXKit
//
// Created by vincentneo on 11/05/2018.
// Copyright (c) 2018 vincentneo. All rights reserved.
//
import UIKit
import CoreGPX
class ViewController: UIViewController {
var tracks = [GPXTrack]()
var waypoints = [GPXWaypoint]()
override func viewDidLoad() {
super.viewDidLoad()
// Example of parsing a GPX file from a sample URL
let urlString : String = "https://raw.githubusercontent.com/gps-touring/sample-gpx/master/BrittanyJura/Courgenay_Ballon-DAlsace.gpx"
let url: URL = URL(string: urlString)!
// GPXRoot object that contains all the data parsed from GPXParser.
guard let gpx = GPXParser(withURL: url)?.parsedData() else { return }
self.tracks = gpx.tracks
self.waypoints = gpx.waypoints
// This example prints all the waypoints's latitude, longitude and date from the GPX file.
for waypoint in self.waypoints {
print("waypoint-latitude: \(waypoint.latitude ?? 0)")
print("waypoint-longitude: \(waypoint.longitude ?? 0)")
print("waypoint-date: \(waypoint.time ?? Date())")
}
// This example prints all the trackpoint's latitude, longitude and date from the GPX file.
for track in self.tracks {
for tracksegment in track.segments {
for trackpoint in tracksegment.points {
print("trackpoint-latitude: \(trackpoint.latitude ?? 0)")
print("trackpoint-longitude: \(trackpoint.longitude ?? 0)")
print("trackpoint-date: \(trackpoint.time ?? Date())")
}
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}