[英]iOS - Open Apple Maps with latitude and longitude directions
我正在开发一个应用程序,需要打开一个 Apple Maps 会话,并传入纬度和经度坐标以从用户当前位置获取到该位置的路线。
我知道这可以在我已经在做的谷歌地图中完成,但是当尝试在 Apple Maps 中打开 URL 时,它只会打开这个地方,而不是从用户当前位置到目的地的路线。
这是我一直在使用的 URL 方案:
http://maps.apple.com/?ll=(someLatitude),(someLongitute)
代码:
UIApplication.sharedApplication().openURL(NSURL(string:"http://maps.apple.com/?ll=\(locationLat),\(locationlong)")!)
任何帮助将不胜感激。 谢谢!
试试这个代码,AppleMap 将打开从设备当前位置到指定坐标位置标记的方向。
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])
尝试使用
NSURL(string:"http://maps.apple.com/?saddr=\(currentLat),\(currentLong)&daddr=\(destinationLat),\(destinationLong)")!
currentLat currentLong 是用户当前位置,destinationLat destinationLong 是目的地位置。
更多参数(例如:传输类型)请看这里
基于幼虫的回答,但我建议您使用"maps://"
URL 方案而不是"http://maps.apple.com/"
来绕过打开 Safari。
像这里:
URL(string: "maps://?saddr=\(currentLat),\(currentLong)&daddr=\(destinationLat),\(destinationLong)")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.