ios - NMACoreRouter calculateRouteWithStops 无回调(快速)

标签 ios swift here-api here-ios

我正在尝试在 Swift 中使用 Here API 创建路由,但我遇到了一些问题,因为从未调用完成 block ,所以我无法确切知道问题出在哪里。 这是我的代码:

let coreRoute = NMACoreRouter()

let startPoint = NMAGeoCoordinates(latitude: latitude1, longitude: longitude1)
let waypoint1 = NMAWaypoint(geoCoordinates: startPoint)
let middlePoint = NMAGeoCoordinates(latitude: latitude2, longitude: longitude2)
let waypoint2 = NMAWaypoint(geoCoordinates: middlePoint, waypointType: NMAWaypointType.ViaWaypoint)
let endPoint = NMAGeoCoordinates(latitude: latitude3, longitude: longitude3)
let waypoint3 = NMAWaypoint(geoCoordinates: endPoint, waypointType: NMAWaypointType.StopWaypoint)

let stopList = [waypoint1, waypoint2, waypoint3] // I have also tried adding the NMAGeoCoordinates to array but still no callback

let routingMode = NMARoutingMode(routingType: NMARoutingType.Fastest, transportMode: NMATransportMode.Car, routingOptions: 0)

coreRoute.calculateRouteWithStops(stopList, routingMode: routingMode) { (routeResult: NMARouteResult?, error: NMARoutingError?) in
    if error == nil && routeResult != nil && routeResult!.routes.count > 0 {
        let route = routeResult!.routes.first as! NMARoute
        let mapRoute = NMAMapRoute(route: route)
        self.mapView.addMapObject(mapRoute)
    } else {
        // Handle error    
    }
}

有人知道这个问题吗?

附言app id、app code和license key都没有问题。在 AppDelegate 中成功设置 NMAApplicationContext

最佳答案

找到解决方案!

您需要将NMACoreRouter 对象声明为类变量。

class <Class_Name> {

    var coreRouter: NMACoreRouter!

    func <Your_Function>() {

        coreRoute = NMACoreRouter()

        let startPoint = NMAGeoCoordinates(latitude: latitude1, longitude: longitude1)
        let waypoint1 = NMAWaypoint(geoCoordinates: startPoint)
        let middlePoint = NMAGeoCoordinates(latitude: latitude2, longitude: longitude2)
        let waypoint2 = NMAWaypoint(geoCoordinates: middlePoint, waypointType: NMAWaypointType.ViaWaypoint)
        let endPoint = NMAGeoCoordinates(latitude: latitude3, longitude: longitude3)
        let waypoint3 = NMAWaypoint(geoCoordinates: endPoint, waypointType: NMAWaypointType.StopWaypoint)

        let stopList = [waypoint1, waypoint2, waypoint3] // I have also tried adding the NMAGeoCoordinates to array but still no callback

        let routingMode = NMARoutingMode(routingType: NMARoutingType.Fastest, transportMode: NMATransportMode.Car, routingOptions: 0)

        coreRoute.calculateRouteWithStops(stopList, routingMode: routingMode) { (routeResult: NMARouteResult?, error: NMARoutingError?) in
            if error == nil && routeResult != nil && routeResult!.routes.count > 0 {
                let route = routeResult!.routes.first as! NMARoute
                let mapRoute = NMAMapRoute(route: route)
                self.mapView.addMapObject(mapRoute)
            } else {
                // Handle error    
            }
        }      
    }    
}   

编辑:导航代码

let navigationManager = NMANavigationManager.sharedNavigationManager()
navigationManager.delegate = self
navigationManager.map = mapView
navigationManager.startTurnByTurnNavigationWithRoute(route)
navigationManager.startTrackingWithTransportMode(.Car)

//Simulation
sharedPositioningManager.dataSource = NMARoutePositionSource(route: route)

关于ios - NMACoreRouter calculateRouteWithStops 无回调(快速),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39657794/

相关文章:

ios - secItemCopyMatching 返回零数据

ios - swift 2 iOS 9 和 SQLite

ios - 是否可以拥有一个模板并根据页面控件中的数组计数添加一定数量的 View Controller ?

ios - 从 Here Api 计算 ETA 后未收到回调

javascript - 如何从 HERE map 中删除现有标记和信息气泡

ios - viewDidLoad() swift4.1 中的 ReverseGeocodeLocation 补全用法

ios - 用户登录 IOS 后绕过 facebook 登录 View

ios - 将数据从一个 tableViewController/Swift 文件传递​​到另一个文件,无需转场

ios - 过滤计算路线时将使用的道路

android - 这里的 map 不起作用