iOS-使用经纬度方向打开Apple Maps [英] iOS - Open Apple Maps with latitude and longitude directions

查看:88
本文介绍了iOS-使用经纬度方向打开Apple Maps的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个需要打开Apple Maps会话的应用程序,并传递经纬度坐标以从用户当前位置获取到该位置的路线。

I am developing an application needs to open an Apple Maps session, and pass in latitude and longitude coordinates to get directions to that location from a users current location.

我知道这可以在已经做过的google地图中完成,但是当尝试在Apple Maps中打开URL时,它只是打开位置,而不是从用户当前位置到目的地的方向。

I know this can be done in google maps which I am already doing, but when attempting to open the URL in Apple Maps it just opens the place not the directions from a users current location to their destination.

这是我一直在使用的URL方案:

Here is the URL scheme I have been using:

http://maps.apple.com/?ll=(someLatitude),(someLongitute)

代码:

UIApplication.sharedApplication().openURL(NSURL(string:"http://maps.apple.com/?ll=\(locationLat),\(locationlong)")!)

任何帮助将不胜感激。谢谢!

Any help would be greatly appreciated. Thanks!

推荐答案

尝试使用此代码,AppleMap将打开,其方向标记为从设备的当前位置到指定坐标的位置。

Try this code, AppleMap will open up with the directions marked from device's current location to the location specified the coordinates.

        let coordinate = CLLocationCoordinate2DMake(currentLat, currentLong)
        let mapItem = MKMapItem(placemark: MKPlacemark(coordinate: coordinate, addressDictionary:nil))
        mapItem.name = "Destination/Target Address or Name"
        mapItem.openInMapsWithLaunchOptions([MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving])

这篇关于iOS-使用经纬度方向打开Apple Maps的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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