iosswiftapple-maps

Opening Apple Maps with Custom Pin Image Using Swift


I have a requirement where I need to open Apple's Maps application from my app with coordinates and a custom pin image. I am able to open the Maps application with coordinates but not with the custom pin image. I searched online and found that custom pin images can be set with MapKit, but I want to do it with Apple's Maps application. Is this possible to do with Swift? Any sort of help or direction would be greatly appreciated.

My code to open the Apple maps application:

func openAppleMap() {
    guard let lat = destinationLat else {return}
    guard let long = destinationLng else {return}
    let coordinate = CLLocationCoordinate2DMake(lat,long)
    let mapItem = MKMapItem(placemark: MKPlacemark(coordinate: coordinate, addressDictionary: nil))
    mapItem.name = "Destination"
    mapItem.openInMaps(launchOptions: [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving])
}

There is no option to pass the custom pin image.


Solution

  • I don't think what you are asking for is possible.

    You could display a map within your app using a custom pin image (Using the MapKit framework as you describe.) However I don't believe there is any mechanism to pass a custom pin image to Apple's Maps application.