NMANavigationManagerDelegate在这里不工作MapiOS SDK

3gtaxfhh  于 2022-11-26  发布在  iOS
关注(0)|答案(3)|浏览(164)

我使用的是HERE iOS SDK,我正在实现一个turn-by-turn导航,但是没有调用NMANavigationManagerDelegatedidUpdateManeuvers方法或任何其他方法。
当我尝试模拟移动并使用时:

let source = NMARoutePositionSource(route: route.route)
NMAPositioningManager.sharedInstance().dataSource = source

所有工作正常,但当我模拟移动通过GPX文件或在现场测试时,委托的方法没有被调用...
我的代码:

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
    }
}

我想跟踪,当我应该改变操纵或当我需要创建一个新的路线,如果用户走错了路。我将感谢帮助。

ctehm74n

ctehm74n1#

您的代码段对我有效。请确保您没有收到任何控制台错误:

Access to this operation is denied.

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要求在Info.plist中设置NSMotionUsageDescription密钥。您可以检查NMADevicePositionSource是否适用。
要使用GPX文件模拟运动,请使用NMALoggedPositionSource
要强制定位广播,可以使用startPositioning

mfpqipee

mfpqipee2#

您需要确保正确设置类以接收委托行为。
查看此问题的答案,尤其是MakeAppPie中的第二个问题。Delegates in swift?
确保您已遵循所有步骤。

qlfbtfca

qlfbtfca3#

也许你错过了这条线

navigationManager.setTrafficAvoidanceMode(.manual)

我也有同样的问题:/

相关问题