diff --git a/Navigation-Examples.xcodeproj/project.pbxproj b/Navigation-Examples.xcodeproj/project.pbxproj index c87fd042..468b1cc2 100644 --- a/Navigation-Examples.xcodeproj/project.pbxproj +++ b/Navigation-Examples.xcodeproj/project.pbxproj @@ -40,6 +40,7 @@ C346744E263C57610068A65E /* Beta-Query-Parameters.swift in Sources */ = {isa = PBXBuildFile; fileRef = C346744D263C57610068A65E /* Beta-Query-Parameters.swift */; }; C35F1E4D2656967E00EC54CD /* Offline-Regions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C35F1E4C2656967E00EC54CD /* Offline-Regions.swift */; }; C3893F1C25F96BDC0058A987 /* Custom-Waypoints.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3893F1B25F96BDC0058A987 /* Custom-Waypoints.swift */; }; + C3D9C06D27B59E7000F6C0B3 /* Search.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3D9C06C27B59E7000F6C0B3 /* Search.swift */; }; C52BAA782040D5030086EC6B /* Custom-Destination-Marker.swift in Sources */ = {isa = PBXBuildFile; fileRef = C52BAA772040D5030086EC6B /* Custom-Destination-Marker.swift */; }; C58FB85A1FE899B800C4B491 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C58FB8591FE899B800C4B491 /* AppDelegate.swift */; }; C58FB8611FE899B800C4B491 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C58FB8601FE899B800C4B491 /* Assets.xcassets */; }; @@ -94,6 +95,7 @@ C346744D263C57610068A65E /* Beta-Query-Parameters.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Beta-Query-Parameters.swift"; sourceTree = ""; }; C35F1E4C2656967E00EC54CD /* Offline-Regions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Offline-Regions.swift"; sourceTree = ""; }; C3893F1B25F96BDC0058A987 /* Custom-Waypoints.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Custom-Waypoints.swift"; sourceTree = ""; }; + C3D9C06C27B59E7000F6C0B3 /* Search.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Search.swift; sourceTree = ""; }; C52BAA772040D5030086EC6B /* Custom-Destination-Marker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Custom-Destination-Marker.swift"; sourceTree = ""; }; C58FB8561FE899B800C4B491 /* Navigation-Examples.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Navigation-Examples.app"; sourceTree = BUILT_PRODUCTS_DIR; }; C58FB8591FE899B800C4B491 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -246,6 +248,7 @@ C58FB8721FE98AEB00C4B491 /* Styled-UI-Elements.swift */, C58FB8761FE98B0E00C4B491 /* Waypoint-Arrival-Screen.swift */, 8DF510731FEB08F70049DB9C /* Embedded-Navigation.swift */, + C3D9C06C27B59E7000F6C0B3 /* Search.swift */, 8D6D36A620001F0400C2B61B /* EmbeddedExamples.storyboard */, C5F130A51FEB2D7800463E86 /* Advanced.swift */, C346744D263C57610068A65E /* Beta-Query-Parameters.swift */, @@ -279,7 +282,6 @@ 4EF74F60792B221A1A61A3CE /* Pods-Navigation-Examples.debug.xcconfig */, A8BC0BE26AF9683D3B034741 /* Pods-Navigation-Examples.release.xcconfig */, ); - name = Pods; path = Pods; sourceTree = ""; }; @@ -334,6 +336,8 @@ dependencies = ( ); name = "Navigation-Examples"; + packageProductDependencies = ( + ); productName = "Navigation Examples"; productReference = C58FB8561FE899B800C4B491 /* Navigation-Examples.app */; productType = "com.apple.product-type.application"; @@ -369,6 +373,8 @@ Base, ); mainGroup = C58FB84D1FE899B800C4B491; + packageReferences = ( + ); productRefGroup = C58FB8571FE899B800C4B491 /* Products */; projectDirPath = ""; projectRoot = ""; @@ -462,6 +468,7 @@ "${PODS_XCFRAMEWORKS_BUILD_DIR}/MapboxCoreMaps/MapboxCoreMaps.framework/MapboxCoreMaps", "${PODS_XCFRAMEWORKS_BUILD_DIR}/MapboxMobileEvents/MapboxMobileEvents.framework/MapboxMobileEvents", "${PODS_XCFRAMEWORKS_BUILD_DIR}/MapboxNavigationNative/MapboxNavigationNative.framework/MapboxNavigationNative", + "${PODS_XCFRAMEWORKS_BUILD_DIR}/MapboxSearch/MapboxSearch.framework/MapboxSearch", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( @@ -477,6 +484,7 @@ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxCoreMaps.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxMobileEvents.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxNavigationNative.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxSearch.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -576,6 +584,7 @@ "${PODS_XCFRAMEWORKS_BUILD_DIR}/MapboxCoreMaps/MapboxCoreMaps.framework/MapboxCoreMaps", "${PODS_XCFRAMEWORKS_BUILD_DIR}/MapboxMobileEvents/MapboxMobileEvents.framework/MapboxMobileEvents", "${PODS_XCFRAMEWORKS_BUILD_DIR}/MapboxNavigationNative/MapboxNavigationNative.framework/MapboxNavigationNative", + "${PODS_XCFRAMEWORKS_BUILD_DIR}/MapboxSearch/MapboxSearch.framework/MapboxSearch", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( @@ -591,6 +600,7 @@ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxCoreMaps.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxMobileEvents.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxNavigationNative.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxSearch.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -628,6 +638,7 @@ 2B521D502409240E00984CF8 /* CustomBottomBannerView.swift in Sources */, B480E428261E4C4600C16FA0 /* Route-Alerts.swift in Sources */, C58FB8771FE98B0E00C4B491 /* Waypoint-Arrival-Screen.swift in Sources */, + C3D9C06D27B59E7000F6C0B3 /* Search.swift in Sources */, C35F1E4D2656967E00EC54CD /* Offline-Regions.swift in Sources */, C5F130A61FEB2D7800463E86 /* Advanced.swift in Sources */, C58FB86C1FE89CEC00C4B491 /* ExampleContainerViewController.swift in Sources */, diff --git a/Navigation-Examples/Constants.swift b/Navigation-Examples/Constants.swift index 173fa958..fc5cb16a 100644 --- a/Navigation-Examples/Constants.swift +++ b/Navigation-Examples/Constants.swift @@ -21,6 +21,15 @@ let listOfExamples: [NamedController] = [ storyboard: nil, pushExampleToViewController: true ), + ( + name: "Search Integration", + description:""" + Demonstrates how to integrate the Mapbox Search SDK with Mapbox Navigation + """, + controller: SearchViewController.self, + storyboard: nil, + pushExampleToViewController: true + ), ( name: "Basic", description: "A basic hello world example showing how to create a navigation experience using the fewest lines of code possible.", diff --git a/Navigation-Examples/Examples/Search.swift b/Navigation-Examples/Examples/Search.swift new file mode 100644 index 00000000..3927695a --- /dev/null +++ b/Navigation-Examples/Examples/Search.swift @@ -0,0 +1,103 @@ +import UIKit +import MapboxCoreNavigation +import MapboxNavigation +import MapboxDirections +import MapboxMaps +import MapboxSearch + +class SearchViewController: UIViewController, NavigationMapViewDelegate, NavigationViewControllerDelegate, UISearchResultsUpdating, UITableViewDataSource { + + var navigationMapView: NavigationMapView! + var navigationRouteOptions: NavigationRouteOptions! + + let searchEngine = SearchEngine() + var searchController: UISearchController! + var tableView: UITableView! + + var searchSuggestions: [SearchSuggestion] = [] + + var isSearchBarEmpty: Bool { + return searchController.searchBar.text?.isEmpty ?? true + } + + // MARK: - UIViewController lifecycle methods + + override func viewDidLoad() { + super.viewDidLoad() + + searchController = UISearchController(searchResultsController: nil) + searchController.searchResultsUpdater = self + searchController.searchBar.placeholder = "Where to?" + self.definesPresentationContext = true + searchController.searchBar.sizeToFit() + + tableView = UITableView() + tableView.dataSource = self + tableView.tableHeaderView = searchController.searchBar + view.addSubview(tableView) + + searchEngine.delegate = self + +// view.addSubview(navigationMapView) +// view.setNeedsLayout() + } + +// override func viewWillAppear(_ animated: Bool) { +// super.viewWillAppear(animated) +// searchController.searchBar.becomeFirstResponder() +// } + + // Override layout lifecycle callback to be able to style the start button. + override func viewDidLayoutSubviews() { + super.viewDidLayoutSubviews() + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "TableCell", for: indexPath) as UITableViewCell + cell.textLabel?.text = searchSuggestions[indexPath.row].name + return cell + } + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return searchSuggestions.count + } + + func updateSearchResults(for searchController: UISearchController) { + if let searchText = searchController.searchBar.text { + searchEngine.query = searchText + tableView.reloadData() + searchEngine.reverseGeocoding(options: <#T##ReverseGeocodingOptions#>, completion: <#T##(Result<[SearchResult], SearchError>) -> Void#>) + } + } + + // Send search results to Nav SDK +// func handleSearchResultSelection(_ searchResult: SearchResult) { +// let coordinate = searchResult.routablePoints?.first?.point ?? searchResult.coordinate +// let destinationWaypoint = Waypoint(coordinate: coordinate, name: "\(searchResult.name)") +// let navigationRouteOptions = NavigationRouteOptions(waypoints: [userWaypoint, destinationWaypoint]) +// Directions.calculateRoutes(navigationRouteOptions) { [weak self (session, result) in +// switch result { +// case .failure(let error): +// print(error) +// case .success(let response): +// // Handle RouteResponse +// } +// } +// } +} + +extension SearchViewController: SearchEngineDelegate { + func resultResolved(result: SearchResult, searchEngine: SearchEngine) { + print("FIX ME!") + } + + func searchErrorHappened(searchError: SearchError, searchEngine: SearchEngine) { + print("Error during search: \(searchError)") + } + + func suggestionsUpdated(suggestions: [SearchSuggestion], searchEngine: SearchEngine) { + // Handle suggestions + searchSuggestions = suggestions + updateSearchResults(for: searchController) + } +} diff --git a/Podfile b/Podfile index 7811a67f..f888193b 100644 --- a/Podfile +++ b/Podfile @@ -3,8 +3,9 @@ install! 'cocoapods', :warn_for_unused_master_specs_repo => false platform :ios, '11.0' use_frameworks! -pod 'MapboxCoreNavigation', '~> 2.0' -pod 'MapboxNavigation', '~> 2.0' +pod 'MapboxCoreNavigation', '2.2.0' +pod 'MapboxNavigation', '2.2.0' +pod 'MapboxSearch', '1.0.0-beta.20' target 'Navigation-Examples' do end diff --git a/Podfile.lock b/Podfile.lock index becda88d..108dd02b 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -17,20 +17,24 @@ PODS: - MapboxMobileEvents (1.0.6) - MapboxNavigation (2.2.0): - MapboxCoreNavigation (= 2.2.0) - - MapboxMaps (= 10.2.0) + - MapboxMaps (~> 10.2) - MapboxMobileEvents (~> 1.0) - MapboxSpeech (~> 2.0) - Solar-dev (~> 3.0) - MapboxNavigationNative (83.0.0): - MapboxCommon (~> 21.0) + - MapboxSearch (1.0.0-beta.20): + - MapboxCommon (~> 21.0.0) + - MapboxMobileEvents (~> 1.0.6) - MapboxSpeech (2.0.0) - Polyline (5.0.2) - Solar-dev (3.0.1) - Turf (2.1.0) DEPENDENCIES: - - MapboxCoreNavigation (~> 2.0) - - MapboxNavigation (~> 2.0) + - MapboxCoreNavigation (= 2.2.0) + - MapboxNavigation (= 2.2.0) + - MapboxSearch (= 1.0.0-beta.20) SPEC REPOS: trunk: @@ -42,6 +46,7 @@ SPEC REPOS: - MapboxMobileEvents - MapboxNavigation - MapboxNavigationNative + - MapboxSearch - MapboxSpeech - Polyline - Solar-dev @@ -54,13 +59,14 @@ SPEC CHECKSUMS: MapboxDirections: aaa6f1ae1612692ef3b4211d20d22404ad8ef607 MapboxMaps: 1ed477cbe573a9e740801dfc9c636ef33bbc3f54 MapboxMobileEvents: 14d7ac3ee95b4142c4fec2205dfd48ff453e8871 - MapboxNavigation: 77fce7e09f1323a1f10c5ee5d9c238aaee2d7d85 + MapboxNavigation: e63908a18a74cc6d629c262ee28c9ab0a370388e MapboxNavigationNative: a82594cb6fa26c129e2f1a08d1466c3f98cdc999 + MapboxSearch: 3544f86d42139789bc2f868c567d627157f45209 MapboxSpeech: e4ed02984444b6373374c72c369edaf045cc490c Polyline: fce41d72e1146c41c6d081f7656827226f643dff Solar-dev: 4612dc9878b9fed2667d23b327f1d4e54e16e8d0 Turf: d1220730a00b50a9fb5862c1fb6a5dd698c9e367 -PODFILE CHECKSUM: ade747cd70b06f12dd4076e55177eb029b4813b0 +PODFILE CHECKSUM: 38d8c2de2a1dfaf4dbb57940a6d54d169f038e8e COCOAPODS: 1.11.2