forked from merlos/iOS-Open-GPX-Tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGPXWaypoint+MKAnnotation.swift
79 lines (69 loc) · 2.25 KB
/
GPXWaypoint+MKAnnotation.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// GPXPin.swift
// OpenGpxTracker
//
// Created by merlos on 16/09/14.
//
import Foundation
import MapKit
import CoreGPX
///
/// Extends GPXWaypoint to support the MKAnnotation protocol. It allows to
/// add the waypoint as a pin in the map
///
extension GPXWaypoint : MKAnnotation {
///
/// Inits the point with a coordinate
///
convenience init (coordinate: CLLocationCoordinate2D) {
self.init(latitude: coordinate.latitude, longitude: coordinate.longitude)
//set default title and subtitle
// Default title now
let timeFormat = DateFormatter()
timeFormat.dateStyle = DateFormatter.Style.none
timeFormat.timeStyle = DateFormatter.Style.medium
//timeFormat.setLocalizedDateFormatFromTemplate("HH:mm:ss")
let subtitleFormat = DateFormatter()
//dateFormat.setLocalizedDateFormatFromTemplate("MMM dd, yyyy")
subtitleFormat.dateStyle = DateFormatter.Style.medium
subtitleFormat.timeStyle = DateFormatter.Style.medium
let now = Date()
self.time = now
self.title = timeFormat.string(from: now)
self.subtitle = subtitleFormat.string(from: now)
}
convenience init (coordinate: CLLocationCoordinate2D, altitude: CLLocationDistance?) {
self.init(coordinate: coordinate)
self.elevation = altitude
}
/// Title displayed on the annotation bubble.
/// Is the attribute name of the waypoint.
public var title: String? {
set {
self.name = newValue
}
get {
return self.name
}
}
/// Subtitle displayed on the annotation bubble
/// Description of the GPXWaypoint.
public var subtitle: String? {
set {
self.desc = newValue
}
get {
return self.desc
}
}
///Annotation coordinates. Returns/Sets the waypoint latitude and longitudes.
public var coordinate: CLLocationCoordinate2D {
set {
self.latitude = newValue.latitude
self.longitude = newValue.longitude
}
get {
return CLLocationCoordinate2D(latitude: self.latitude!, longitude: CLLocationDegrees(self.longitude!))
}
}
}