我遵循这个例子:turn-by-turn-navigation-ios-swift
这就是我的更新地图功能的样子:
private func updateMapRoute(with route: NMARoute!) {
// remove previously created map route from map
if let previousMapRoute = mapRoute {
mapView.remove(mapObject:previousMapRoute)
}
guard let unwrappedRoute = route else {
return
}
mapRoute = NMAMapRoute(unwrappedRoute)
mapRoute?.traveledColor = .clear
_ = mapRoute.map{ mapView?.add(mapObject: $0) }
// In order to see the entire route, we orientate the
// map view accordingly
if let boundingBox = unwrappedRoute.boundingBox {
geoBoundingBox = boundingBox
mapView.set(boundingBox: boundingBox, animation: .linear)
}
}
然而,previos 路线并未从地图中删除。
mapRoute 变量定义如下:private var mapRoute : NMAMapRoute!
我在忽略什么吗?先感谢您!BR。