-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced the Waypoint and Tracepoint classes with separate classes for requests and responses.
- Loading branch information
Showing
17 changed files
with
404 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,44 @@ | ||
import Foundation | ||
import CoreLocation | ||
|
||
/** | ||
A `Tracepoint` represents a location matched to the road network. | ||
*/ | ||
public class Tracepoint: Waypoint { | ||
public extension Match { | ||
/** | ||
Number of probable alternative matchings for this tracepoint. A value of zero indicates that this point was matched unambiguously. | ||
A tracepoint represents a location matched to the road network. | ||
*/ | ||
public let alternateCount: Int | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
case alternateCount = "alternatives_count" | ||
} | ||
|
||
init(coordinate: CLLocationCoordinate2D, alternateCount: Int?, name: String?) { | ||
self.alternateCount = alternateCount ?? NSNotFound | ||
super.init(coordinate: coordinate, name: name) | ||
} | ||
|
||
required public init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
alternateCount = try container.decode(Int.self, forKey: .alternateCount) | ||
try super.init(from: decoder) | ||
struct Tracepoint: Matchpoint, Equatable { | ||
// MARK: Positioning the Waypoint | ||
|
||
/** | ||
The geographic coordinate of the waypoint, snapped to the road network. | ||
*/ | ||
public var coordinate: CLLocationCoordinate2D | ||
|
||
/** | ||
The straight-line distance from this waypoint to the corresponding waypoint in the `RouteOptions` or `MatchOptions` object. | ||
|
||
The requested waypoint is snapped to the road network. This property contains the straight-line distance from the original requested waypoint’s `DirectionsOptions.Waypoint.coordinate` property to the `coordinate` property. | ||
*/ | ||
public var correction: CLLocationDistance | ||
|
||
// MARK: Determining the Degree of Confidence | ||
|
||
/** | ||
Number of probable alternative matchings for this tracepoint. A value of zero indicates that this point was matched unambiguously. | ||
*/ | ||
public var countOfAlternatives: Int | ||
} | ||
|
||
public override func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encode(alternateCount, forKey: .alternateCount) | ||
try super.encode(to: encoder) | ||
} | ||
|
||
extension Match.Tracepoint: Codable { | ||
private enum CodingKeys: String, CodingKey { | ||
case coordinate = "location" | ||
case correction = "distance" | ||
case countOfAlternatives = "alternatives_count" | ||
} | ||
} | ||
|
||
extension Tracepoint { //Equatable | ||
public static func ==(lhs: Tracepoint, rhs: Tracepoint) -> Bool { | ||
let superEquals = (lhs as Waypoint == rhs as Waypoint) | ||
return superEquals && lhs.alternateCount == rhs.alternateCount | ||
extension Match.Tracepoint: CustomStringConvertible { | ||
public var description: String { | ||
return "<latitude: \(coordinate.latitude); longitude: \(coordinate.longitude)>" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.