以前的路线未从地图中删除:此处 IOS - Swift SDK
Previos route is not getting removed from the map : HERE IOS - Swift SDK
我正在遵循这个例子: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: [=12=]) }
// 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)
}
}
但之前的路线并未从地图中删除。
mapRoute 变量定义如下:private var mapRoute : NMAMapRoute!
我是不是忽略了什么?
先感谢您!
BR.
您必须在创建新路线之前删除之前的路线。在调用这个函数之前添加这个
// remove previously created map route from map
if let previousMapRoute = mapRoute {
mapView.remove(mapObject:previousMapRoute)
}
实际上,在您的情况下,它正在丢失对 MapRoute 的引用。您需要将之前的 NMARoute 保存在一个对象中,并使用该 NMARoute 获取 NMAMapRoute 以访问和删除之前的地图路线。
if let previousMapRoute = NMAMapRoute(previoudRoute) {
mapView.remove(mapObject:previousMapRoute)
}
将上面的代码替换为你的代码,并在 previousRoute 对象中保存之前的路线。
我正在遵循这个例子: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: [=12=]) }
// 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)
}
}
但之前的路线并未从地图中删除。
mapRoute 变量定义如下:private var mapRoute : NMAMapRoute!
我是不是忽略了什么? 先感谢您! BR.
您必须在创建新路线之前删除之前的路线。在调用这个函数之前添加这个
// remove previously created map route from map
if let previousMapRoute = mapRoute {
mapView.remove(mapObject:previousMapRoute)
}
实际上,在您的情况下,它正在丢失对 MapRoute 的引用。您需要将之前的 NMARoute 保存在一个对象中,并使用该 NMARoute 获取 NMAMapRoute 以访问和删除之前的地图路线。
if let previousMapRoute = NMAMapRoute(previoudRoute) {
mapView.remove(mapObject:previousMapRoute)
}
将上面的代码替换为你的代码,并在 previousRoute 对象中保存之前的路线。