Open Apple Maps for navigation with destination name set

前端 未结 1 949
广开言路
广开言路 2021-01-22 05:28

I am fetching location data (like the coordinates used below) from Google\'s Places API.

When linking to Apple Maps for navigation from my app, I am currently using:

相关标签:
1条回答
  • 2021-01-22 06:19

    Try with this function, you only need to pass the coordinates and place name, this works, I use this in several projects

    static func openMapsAppWithLocation(coordinates:CLLocationCoordinate2D,placeName:String)
    {
        let regionDistance:CLLocationDistance = 10000
        let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates, regionDistance, regionDistance)
        let options = [
            MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center),
            MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span)
        ]
        let placemark = MKPlacemark(coordinate: coordinates, addressDictionary: nil)
        let mapItem = MKMapItem(placemark: placemark)
        mapItem.name = placeName
        mapItem.openInMaps(launchOptions: options)
    }
    

    Hope this helps

    0 讨论(0)
提交回复
热议问题