Home Getting Directions From an Annotation on the Map
Reply: 0

Getting Directions From an Annotation on the Map

user1070 Published in April 25, 2018, 12:32 pm

I am trying to get directions from any annotations that are found on my map. I am using CloudKit as a database to store all my user's information. The annotations use the location index in CloudKit to map out their location on the map. Every time I run my code the annotation comes back as nil, how do I get my code to recognize the location from the annotation and return directions from apple maps?

@IBAction func getDirections(_ sender: Any) {

    let view = MKPointAnnotation().coordinate

    print("Annotation: \(String(describing: view ))")

    let currentLocMapItem = MKMapItem.forCurrentLocation()

    let selectedPlacemark = MKPlacemark(coordinate: view, addressDictionary: nil)
    let selectedMapItem = MKMapItem(placemark: selectedPlacemark)

    let mapItems = [selectedMapItem, currentLocMapItem]

    let launchOptions = [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]

    MKMapItem.openMaps(with: mapItems, launchOptions:launchOptions)

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.302169 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO