Reputation: 303
I'm using the HERE iOS SDK and I'm implementing a turn-by-turn navigation but method didUpdateManeuvers
of NMANavigationManagerDelegate
or any else is not called.
When I try to simulate move and use:
let source = NMARoutePositionSource(route: route.route)
NMAPositioningManager.sharedInstance().dataSource = source
all works fine, but when I simulate move through GPX
file or test in live, methods of delegate is not called...
My code:
class HereMapViewController: UIViewController {
@IBOutlet private weak var mapView: NMAMapView!
fileprivate var navigationManager = NMANavigationManager.sharedInstance()
var route : NMAMapRoute?
// MARK: - life cycle
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
}
deinit {
navigationManager.stop()
}
// MARK: - private
private func setupUI() {
mapView.copyrightLogoPosition = .center
mapView.zoomLevel = 10
mapView.positionIndicator.isVisible = true
mapView.gestureDelegate = self
navigationManager.voicePackageMeasurementSystem = NMAMeasurementSystem.imperialUS
navigationManager.backgroundNavigationEnabled = true
navigationManager.isVoiceEnabled = true
navigationManager.delegate = self
setupRoute()
}
private func setupRoute() {
guard let mapRoute = route, let routeStart = mapRoute.route.start else {
return
}
let start = NMAGeoCoordinates(latitude: routeStart.navigablePosition.latitude,
longitude: routeStart.navigablePosition.longitude)
mapView.add(mapObject: mapRoute)
mapView.set(boundingBox: mapRoute.route.boundingBox!, animation: NMAMapAnimation.none)
startNavigation()
mapView.set(geoCenter: start, animation: .none)
}
private func startNavigation() {
guard let route = route else {
return
}
navigationManager.map = mapView
NMAPositioningManager.sharedInstance().dataSource = NMAHEREPositionSource()
navigationManager.startTurnByTurnNavigation(route.route)
navigationManager.mapTrackingEnabled = false
navigationManager.mapTrackingAutoZoomEnabled = false
navigationManager.mapTrackingOrientation = .dynamic
navigationManager.isSpeedWarningEnabled = true
}
}
//MARK: - NMANavigationManagerDelegate
extension HereMapViewController : NMANavigationManagerDelegate {
// Signifies that there is new instruction information available
func navigationManager(_ navigationManager: NMANavigationManager, didUpdateManeuvers currentManeuver: NMAManeuver?, _ nextManeuver: NMAManeuver?) {
print("didUpdateManeuvers")
}
// Signifies that the system has found a GPS signal
func navigationManagerDidFindPosition(_ navigationManager: NMANavigationManager) {
print("New position has been found")
}
func navigationManager(_ navigationManager: NMANavigationManager, didFindAlternateRoute routeResult: NMARouteResult) {
print("didFindAlternateRoute")
}
func navigationManager(_ navigationManager: NMANavigationManager, didUpdateRoute routeResult: NMARouteResult) {
print("didUpdateRoute")
}
}
//MARK: - NMAMapGestureDelegate
extension HereMapViewController : NMAMapGestureDelegate {
func mapView(_ mapView: NMAMapView, didReceiveTwoFingerPan translation: CGPoint, at location: CGPoint) {
navigationManager.mapTrackingAutoZoomEnabled = false
}
}
I want to track, when I should change manoeuvre or when I need to create a new route if user went the wrong way. I will be grateful for the help.
Upvotes: 1
Views: 490
Reputation: 1
Maybe you miss this line
navigationManager.setTrafficAvoidanceMode(.manual)
I have the same problem :/
Upvotes: 0
Reputation: 170
Your snippet works for me. Make sure you don't get any console errors:
Access to this operation is denied.
or
This app has attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain both “NSLocationAlwaysAndWhenInUseUsageDescription” and “NSLocationWhenInUseUsageDescription” keys with string values explaining to the user how the app uses this data
NMAHEREPositionSource requires NSMotionUsageDescription key to be set in Info.plist. You can check if NMADevicePositionSource works for you.
To simulate movement with GPX file, use NMALoggedPositionSource
To force positioning broadcast, you can use startPositioning
Upvotes: 2
Reputation: 142
You need to make sure you set your class properly to receive delegate behavior.
Check out this question's answers, particularly the second one from MakeAppPie. Delegates in swift?
Make sure you have followed all the steps.
Upvotes: 0