-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make RouteOptions available on route response #122
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,8 @@ import Polyline | |
open class Route: NSObject, NSSecureCoding { | ||
// MARK: Creating a Route | ||
|
||
internal init(profileIdentifier: MBDirectionsProfileIdentifier, legs: [RouteLeg], distance: CLLocationDistance, expectedTravelTime: TimeInterval, coordinates: [CLLocationCoordinate2D]?) { | ||
self.profileIdentifier = profileIdentifier | ||
internal init(routeOptions: RouteOptions, legs: [RouteLeg], distance: CLLocationDistance, expectedTravelTime: TimeInterval, coordinates: [CLLocationCoordinate2D]?) { | ||
self.routeOptions = routeOptions | ||
self.legs = legs | ||
self.distance = distance | ||
self.expectedTravelTime = expectedTravelTime | ||
|
@@ -26,12 +26,12 @@ open class Route: NSObject, NSSecureCoding { | |
- parameter waypoints: An array of waypoints that the route visits in chronological order. | ||
- parameter profileIdentifier: The profile identifier used to request the routes. | ||
*/ | ||
public convenience init(json: [String: Any], waypoints: [Waypoint], profileIdentifier: MBDirectionsProfileIdentifier) { | ||
public convenience init(json: [String: Any], waypoints: [Waypoint], routeOptions: RouteOptions) { | ||
// Associate each leg JSON with a source and destination. The sequence of destinations is offset by one from the sequence of sources. | ||
let legInfo = zip(zip(waypoints.prefix(upTo: waypoints.endIndex - 1), waypoints.suffix(from: 1)), | ||
json["legs"] as? [JSONDictionary] ?? []) | ||
let legs = legInfo.map { (endpoints, json) -> RouteLeg in | ||
RouteLeg(json: json, source: endpoints.0, destination: endpoints.1, profileIdentifier: profileIdentifier) | ||
RouteLeg(json: json, source: endpoints.0, destination: endpoints.1, profileIdentifier: routeOptions.profileIdentifier) | ||
} | ||
let distance = json["distance"] as! Double | ||
let expectedTravelTime = json["duration"] as! Double | ||
|
@@ -46,7 +46,7 @@ open class Route: NSObject, NSSecureCoding { | |
coordinates = nil | ||
} | ||
|
||
self.init(profileIdentifier: profileIdentifier, legs: legs, distance: distance, expectedTravelTime: expectedTravelTime, coordinates: coordinates) | ||
self.init(routeOptions: routeOptions, legs: legs, distance: distance, expectedTravelTime: expectedTravelTime, coordinates: coordinates) | ||
} | ||
|
||
public required init?(coder decoder: NSCoder) { | ||
|
@@ -64,10 +64,10 @@ open class Route: NSObject, NSSecureCoding { | |
distance = decoder.decodeDouble(forKey: "distance") | ||
expectedTravelTime = decoder.decodeDouble(forKey: "expectedTravelTime") | ||
|
||
guard let decodedProfileIdentifier = decoder.decodeObject(of: NSString.self, forKey: "profileIdentifier") as String? else { | ||
guard let options = decoder.decodeObject(of: [RouteOptions.self], forKey: "routeOptions") as? RouteOptions else { | ||
return nil | ||
} | ||
profileIdentifier = MBDirectionsProfileIdentifier(rawValue: decodedProfileIdentifier) | ||
routeOptions = options | ||
} | ||
|
||
open static var supportsSecureCoding = true | ||
|
@@ -82,7 +82,7 @@ open class Route: NSObject, NSSecureCoding { | |
coder.encode(legs, forKey: "legs") | ||
coder.encode(distance, forKey: "distance") | ||
coder.encode(expectedTravelTime, forKey: "expectedTravelTime") | ||
coder.encode(profileIdentifier, forKey: "profileIdentifier") | ||
coder.encode(routeOptions, forKey: "routeOptions") | ||
} | ||
|
||
// MARK: Getting the Route Geometry | ||
|
@@ -156,18 +156,16 @@ open class Route: NSObject, NSSecureCoding { | |
open let expectedTravelTime: TimeInterval | ||
|
||
/** | ||
A string specifying the primary mode of transportation for the route. | ||
|
||
The value of this property is `MBDirectionsProfileIdentifierAutomobile`, `MBDirectionsProfileIdentifierAutomobileAvoidingTraffic`, `MBDirectionsProfileIdentifierCycling`, or `MBDirectionsProfileIdentifierWalking`, depending on the `profileIdentifier` property of the original `RouteOptions` object. This property reflects the primary mode of transportation used for the route. Individual steps along the route might use different modes of transportation as necessary. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Developers may not be aware of this nuance, so we might want to leave it in:
|
||
`RouteOptions` used to create the directions request. | ||
*/ | ||
open let profileIdentifier: MBDirectionsProfileIdentifier | ||
open let routeOptions: RouteOptions | ||
} | ||
|
||
// MARK: Support for Directions API v4 | ||
|
||
internal class RouteV4: Route { | ||
convenience init(json: JSONDictionary, waypoints: [Waypoint], profileIdentifier: MBDirectionsProfileIdentifier) { | ||
let leg = RouteLegV4(json: json, source: waypoints.first!, destination: waypoints.last!, profileIdentifier: profileIdentifier) | ||
convenience init(json: JSONDictionary, waypoints: [Waypoint], routeOptions: RouteOptions) { | ||
let leg = RouteLegV4(json: json, source: waypoints.first!, destination: waypoints.last!, profileIdentifier: routeOptions.profileIdentifier) | ||
let distance = json["distance"] as! Double | ||
let expectedTravelTime = json["duration"] as! Double | ||
|
||
|
@@ -181,6 +179,6 @@ internal class RouteV4: Route { | |
coordinates = nil | ||
} | ||
|
||
self.init(profileIdentifier: profileIdentifier, legs: [leg], distance: distance, expectedTravelTime: expectedTravelTime, coordinates: coordinates) | ||
self.init(routeOptions: routeOptions, legs: [leg], distance: distance, expectedTravelTime: expectedTravelTime, coordinates: coordinates) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,13 @@ class V5Tests: XCTestCase { | |
XCTAssertEqual(task.state, .completed) | ||
} | ||
|
||
let opts = route!.routeOptions | ||
|
||
XCTAssertEqual(opts.profileIdentifier, .automobile) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might as well assert that |
||
XCTAssertTrue(opts.includesSteps) | ||
XCTAssertTrue(opts.includesAlternativeRoutes) | ||
XCTAssertEqual(opts.routeShapeResolution, .full) | ||
|
||
XCTAssertNotNil(route) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this assertion up above any assertions that depend on |
||
XCTAssertNotNil(route!.coordinates) | ||
XCTAssertEqual(route!.coordinates!.count, 28_442) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parameter has been replaced by
routeOptions
.