ran*_*110 11 ios apple-maps swift
我正在开发一个应用程序需要打开Apple Maps会话,并传入纬度和经度坐标以从用户当前位置获取到该位置的路线.
我知道这可以在我已经在做的谷歌地图中完成,但是当试图在Apple Maps中打开URL时,它只会打开地点,而不是从用户当前位置到目的地的路线.
这是我一直使用的URL方案:
http://maps.apple.com/?ll=(someLatitude),(someLongitute)
Run Code Online (Sandbox Code Playgroud)
码:
UIApplication.sharedApplication().openURL(NSURL(string:"http://maps.apple.com/?ll=\(locationLat),\(locationlong)")!)
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.谢谢!
小智 21
试试这段代码,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])
Run Code Online (Sandbox Code Playgroud)
试试用
NSURL(string:"http://maps.apple.com/?saddr=\(currentLat),\(currentLong)&daddr=\(destinationLat),\(destinationLong)")!
Run Code Online (Sandbox Code Playgroud)
with currentLat currentLong是用户的当前位置,destinationLat destinationLong是目标位置.
更多参数(例如:运输类型)请看这里