Apple Mapkit Navigation: Does Mapkit gives callback on reaching destination point?

22 views Asked by At

I am using Apple Mapkit navigation in one of my application, it is working fine when I give start location and destination location. But it does not throw me any callback when it reaches to destination point into my ViewController. Is there any callback to handle this or any other way around to tackle this. Actually on desctination reached I want to switch to next ViewController.

Here is my code:

class AppleMap {
    
    var source: CLLocationCoordinate2D? = nil
    var destination: CLLocationCoordinate2D? = nil

    init(source: CLLocationCoordinate2D, destination: CLLocationCoordinate2D) {
        self.source = source
        self.destination = destination
    }
    
    // If you are calling the coordinate from a Model, don't forgot to pass it in the function parenthesis.
    func present(in viewController: UIViewController, sourceView: UIView) {
        
        if let source = self.source, let destination = self.destination {
            //            CLLocationCoordinate2D(latitude: 51.792014, longitude: -114.105279)
            let source = MKMapItem(placemark: MKPlacemark(coordinate: source))
            source.name = "Source"
            
            let destination = MKMapItem(placemark: MKPlacemark(coordinate: destination))
            destination.name = "Destination"
            
            let okotoks = MKMapItem(placemark: MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: 50.725494, longitude: -113.974947)))
            okotoks.name = "okotoks"
            
            MKMapItem.openMaps(
              with: [source, destination],
              launchOptions: [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]
            )
        }
}

Its calling is like:

let appleMap = AppleMap(source: source, destination: pickupLocation)
appleMap.present(in: self, sourceView: UIView())
0

There are 0 answers