Skip to content
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

Upgrade to navigation SDK v0.40.0 #50

Merged
merged 2 commits into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

142 changes: 0 additions & 142 deletions DocsCode/NavigationTutorial/NavigationTutorialViewController.m

This file was deleted.

26 changes: 17 additions & 9 deletions DocsCode/NavigationTutorial/NavigationTutorialViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import MapboxDirections
class ViewController: UIViewController, MGLMapViewDelegate {
// #-code-snippet: navigation vc-variables-swift
var mapView: NavigationMapView!
var directionsRoute: Route?
var routeOptions: NavigationRouteOptions?
var route: Route?
// #-end-code-snippet: navigation vc-variables-swift

// #-code-snippet: navigation view-did-load-swift
Expand Down Expand Up @@ -66,23 +67,27 @@ class ViewController: UIViewController, MGLMapViewDelegate {
let destination = Waypoint(coordinate: destination, coordinateAccuracy: -1, name: "Finish")

// Specify that the route is intended for automobiles avoiding traffic
let options = NavigationRouteOptions(waypoints: [origin, destination], profileIdentifier: .automobileAvoidingTraffic)
let routeOptions = NavigationRouteOptions(waypoints: [origin, destination], profileIdentifier: .automobileAvoidingTraffic)

// Generate the route object and draw it on the map
_ = Directions.shared.calculate(options) { [unowned self] (waypoints, routes, error) in
self.directionsRoute = routes?.first
_ = Directions.shared.calculate(routeOptions) { [weak self] (session, result) in
guard case let .success(response) = result, let route = response.routes?.first, let strongSelf = self else {
return
}
strongSelf.route = route
strongSelf.routeOptions = routeOptions
// Draw the route on the map after creating it
self.drawRoute(route: self.directionsRoute!)
strongSelf.drawRoute(route: route)
}
}
// #-end-code-snippet: navigation calculate-route-swift

// #-code-snippet: navigation draw-route-swift
func drawRoute(route: Route) {
guard route.coordinateCount > 0 else { return }
guard let routeShape = route.shape, routeShape.coordinates.count > 0 else { return }
// Convert the route’s coordinates into a polyline
var routeCoordinates = route.coordinates!
let polyline = MGLPolylineFeature(coordinates: &routeCoordinates, count: route.coordinateCount)
var routeCoordinates = routeShape.coordinates
let polyline = MGLPolylineFeature(coordinates: &routeCoordinates, count: UInt(routeCoordinates.count))

// If there's already a route line on the map, reset its shape to the new route
if let source = mapView.style?.source(withIdentifier: "route-source") as? MGLShapeSource {
Expand Down Expand Up @@ -110,7 +115,10 @@ class ViewController: UIViewController, MGLMapViewDelegate {

// Present the navigation view controller when the callout is selected
func mapView(_ mapView: MGLMapView, tapOnCalloutFor annotation: MGLAnnotation) {
let navigationViewController = NavigationViewController(for: directionsRoute!)
guard let route = route, let routeOptions = routeOptions else {
return
}
let navigationViewController = NavigationViewController(for: route, routeOptions: routeOptions)
navigationViewController.modalPresentationStyle = .fullScreen
self.present(navigationViewController, animated: true, completion: nil)
}
Expand Down
38 changes: 22 additions & 16 deletions Navigation-Examples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
9613F58822E030AC00D34E24 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9613F58622E030AC00D34E24 /* LaunchScreen.storyboard */; };
9613F58922E030AC00D34E24 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9613F58722E030AC00D34E24 /* Main.storyboard */; };
961FC51422E0268800C72877 /* NavigationTutorialViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961FC4EE22E0260A00C72877 /* NavigationTutorialViewController.swift */; };
961FC51522E0268800C72877 /* NavigationTutorialViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 961FC4EF22E0260A00C72877 /* NavigationTutorialViewController.m */; };
961FC51622E0268B00C72877 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961FC4F122E0260A00C72877 /* AppDelegate.swift */; };
9639244A22E02A520010FE73 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C58FB85D1FE899B800C4B491 /* Main.storyboard */; };
9639244B22E02A820010FE73 /* EmbeddedExamples.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8D6D36A620001F0400C2B61B /* EmbeddedExamples.storyboard */; };
Expand Down Expand Up @@ -52,8 +51,6 @@
961FC4E722E0260A00C72877 /* DocsCode-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DocsCode-Bridging-Header.h"; sourceTree = "<group>"; };
961FC4E822E0260A00C72877 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
961FC4EE22E0260A00C72877 /* NavigationTutorialViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationTutorialViewController.swift; sourceTree = "<group>"; };
961FC4EF22E0260A00C72877 /* NavigationTutorialViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NavigationTutorialViewController.m; sourceTree = "<group>"; };
961FC4F022E0260A00C72877 /* NavigationTutorialViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NavigationTutorialViewController.h; sourceTree = "<group>"; };
961FC4F122E0260A00C72877 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
961FC4F222E0260A00C72877 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
961FC4FE22E0265300C72877 /* DocsCode.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DocsCode.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -143,8 +140,6 @@
isa = PBXGroup;
children = (
961FC4EE22E0260A00C72877 /* NavigationTutorialViewController.swift */,
961FC4EF22E0260A00C72877 /* NavigationTutorialViewController.m */,
961FC4F022E0260A00C72877 /* NavigationTutorialViewController.h */,
);
path = NavigationTutorial;
sourceTree = "<group>";
Expand Down Expand Up @@ -330,10 +325,13 @@
"${PODS_ROOT}/Target Support Files/Pods-Navigation-Examples/Pods-Navigation-Examples-frameworks.sh",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework.dSYM",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/B8CEDF0B-90B7-325D-BA23-1B44AB41FEC9.bcsymbolmap",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/1182BB8D-8A58-30EC-8D04-5E89575ED646.bcsymbolmap",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/EF3F193B-8B19-3D7A-9C4D-CC7ACB8FD1B2.bcsymbolmap",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/AF8AFA46-95A0-3C36-89B4-0A23D7D0A613.bcsymbolmap",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/224E36C4-6533-3853-8416-A668FDC17C35.bcsymbolmap",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/E1D60A9C-E180-3412-BFDB-809E8A1C178E.bcsymbolmap",
"${PODS_ROOT}/MapboxAccounts/MapboxAccounts.framework",
"${BUILT_PRODUCTS_DIR}/MapboxCoreNavigation/MapboxCoreNavigation.framework",
"${BUILT_PRODUCTS_DIR}/MapboxDirections.swift/MapboxDirections.framework",
"${BUILT_PRODUCTS_DIR}/MapboxDirections/MapboxDirections.framework",
"${BUILT_PRODUCTS_DIR}/MapboxMobileEvents/MapboxMobileEvents.framework",
"${BUILT_PRODUCTS_DIR}/MapboxNavigation/MapboxNavigation.framework",
"${PODS_ROOT}/MapboxNavigationNative/MapboxNavigationNative.framework",
Expand All @@ -347,8 +345,11 @@
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mapbox.framework",
"${DWARF_DSYM_FOLDER_PATH}/Mapbox.framework.dSYM",
"${BUILT_PRODUCTS_DIR}/B8CEDF0B-90B7-325D-BA23-1B44AB41FEC9.bcsymbolmap",
"${BUILT_PRODUCTS_DIR}/1182BB8D-8A58-30EC-8D04-5E89575ED646.bcsymbolmap",
"${BUILT_PRODUCTS_DIR}/EF3F193B-8B19-3D7A-9C4D-CC7ACB8FD1B2.bcsymbolmap",
"${BUILT_PRODUCTS_DIR}/AF8AFA46-95A0-3C36-89B4-0A23D7D0A613.bcsymbolmap",
"${BUILT_PRODUCTS_DIR}/224E36C4-6533-3853-8416-A668FDC17C35.bcsymbolmap",
"${BUILT_PRODUCTS_DIR}/E1D60A9C-E180-3412-BFDB-809E8A1C178E.bcsymbolmap",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxAccounts.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxCoreNavigation.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxDirections.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxMobileEvents.framework",
Expand Down Expand Up @@ -429,10 +430,13 @@
"${PODS_ROOT}/Target Support Files/Pods-DocsCode/Pods-DocsCode-frameworks.sh",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework.dSYM",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/B8CEDF0B-90B7-325D-BA23-1B44AB41FEC9.bcsymbolmap",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/1182BB8D-8A58-30EC-8D04-5E89575ED646.bcsymbolmap",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/EF3F193B-8B19-3D7A-9C4D-CC7ACB8FD1B2.bcsymbolmap",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/AF8AFA46-95A0-3C36-89B4-0A23D7D0A613.bcsymbolmap",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/224E36C4-6533-3853-8416-A668FDC17C35.bcsymbolmap",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/E1D60A9C-E180-3412-BFDB-809E8A1C178E.bcsymbolmap",
"${PODS_ROOT}/MapboxAccounts/MapboxAccounts.framework",
"${BUILT_PRODUCTS_DIR}/MapboxCoreNavigation/MapboxCoreNavigation.framework",
"${BUILT_PRODUCTS_DIR}/MapboxDirections.swift/MapboxDirections.framework",
"${BUILT_PRODUCTS_DIR}/MapboxDirections/MapboxDirections.framework",
"${BUILT_PRODUCTS_DIR}/MapboxMobileEvents/MapboxMobileEvents.framework",
"${BUILT_PRODUCTS_DIR}/MapboxNavigation/MapboxNavigation.framework",
"${PODS_ROOT}/MapboxNavigationNative/MapboxNavigationNative.framework",
Expand All @@ -446,8 +450,11 @@
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mapbox.framework",
"${DWARF_DSYM_FOLDER_PATH}/Mapbox.framework.dSYM",
"${BUILT_PRODUCTS_DIR}/B8CEDF0B-90B7-325D-BA23-1B44AB41FEC9.bcsymbolmap",
"${BUILT_PRODUCTS_DIR}/1182BB8D-8A58-30EC-8D04-5E89575ED646.bcsymbolmap",
"${BUILT_PRODUCTS_DIR}/EF3F193B-8B19-3D7A-9C4D-CC7ACB8FD1B2.bcsymbolmap",
"${BUILT_PRODUCTS_DIR}/AF8AFA46-95A0-3C36-89B4-0A23D7D0A613.bcsymbolmap",
"${BUILT_PRODUCTS_DIR}/224E36C4-6533-3853-8416-A668FDC17C35.bcsymbolmap",
"${BUILT_PRODUCTS_DIR}/E1D60A9C-E180-3412-BFDB-809E8A1C178E.bcsymbolmap",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxAccounts.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxCoreNavigation.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxDirections.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxMobileEvents.framework",
Expand All @@ -473,7 +480,6 @@
files = (
961FC51622E0268B00C72877 /* AppDelegate.swift in Sources */,
961FC51422E0268800C72877 /* NavigationTutorialViewController.swift in Sources */,
961FC51522E0268800C72877 /* NavigationTutorialViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Loading