Open Apple Maps for navigation with destination name set

穿精又带淫゛_ 提交于 2019-12-20 02:53:11

问题


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:

https://maps.apple.com/?daddr=[latitude],[longitude]

When Maps opens, it presents the coordinates for a short amount of time before resolving to an address. What I want is for the name of the destination to appear instead of coordinates or an address. Since I am using React Native, I would prefer a javascript-only solution (knowing that this essentially restricts a solution to this question to a url).

I have tried combinations of other parameters listed here to no avail.


回答1:


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



来源:https://stackoverflow.com/questions/45514883/open-apple-maps-for-navigation-with-destination-name-set

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!