打开Apple Maps以进行导航并设置目的地名称 [英] Open Apple Maps for navigation with destination name set

查看:537
本文介绍了打开Apple Maps以进行导航并设置目的地名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Google的Places API获取位置数据(如下面使用的坐标)。

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

当我从我的应用程序链接到Apple Maps进行导航时,我正在使用:

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

https://maps.apple.com/?daddr= [纬度],[经度]

当地图打开时,它会在解析到地址之前显示一小段时间的坐标。 我想要的是显示目的地的名称而不是坐标或地址。由于我使用的是React Native,我会更喜欢一个仅限javascript的解决方案(知道这基本上限制了这个问题的解决方案到网址。)

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.

推荐答案

尝试使用此功能,您只需要传递坐标和地名,这样就行了,我在几个项目中使用它

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)
}

希望这有助于

这篇关于打开Apple Maps以进行导航并设置目的地名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆