iosswifthere-apiheremaps-ios-sdk

Previos route is not getting removed from the map : HERE IOS - Swift SDK


im following this example: turn-by-turn-navigation-ios-swift

THis is how my update map function looks like:

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

Yet the previos route is not getting removed from the map.

The mapRoute variable is defined as this : private var mapRoute : NMAMapRoute!

Am i overlooking something? Thank you in advance! BR.

enter image description here


Solution

  • Actually, in your case, it is losing reference to MapRoute. You need to save the previous NMARoute in one object and get NMAMapRoute using that NMARoute to access and delete previous map route.

    if let previousMapRoute = NMAMapRoute(previoudRoute) {
        mapView.remove(mapObject:previousMapRoute)       
    }
    

    Replace the above code with yours and save the previous route in previousRoute object.