如何打开Google地图以使用Swift显示路线 [英] How to open Google Maps to show route using Swift
问题描述
如何在Swift中实现这一点?
如果任何人有解决方案,请为我提供示例代码。
好的,我自己找到了答案。
如果您想显示来自用户当前位置的路线,请将字段 saddr
留空,并放在字段 daddr中
这就是我的做法
<$ p (); $ p>
if(UIApplication.sharedApplication()。canOpenURL(NSURL(string:comgooglemaps://)!)){
UIApplication.sharedApplication()。openURL(NSURL(string:
comgooglemaps://?saddr =& daddr = \(place.latitude),\(place.longitude)& directionsmode = driving)!)
} else {
NSLog(无法使用comgooglemaps://);
$ b 对于任何进一步的查询,你可以参考这个链接< a href =https://developers.google.com/maps/documentation/ios/urlscheme?hl=zh_CN> Google地图网址计划
I read around the Internet but couldn't find a legit answer. I need to open Google Maps when the user clicks a button to show directions. Start and destination must be automatically filled.
How can I achieve this in Swift?
If anyone has a solution, please provide me with a sample code. The start is always going to be the user's current location.
解决方案 OK I found the answer myself.
If you want to show directions from the user's current location, leave the field saddr
blank and in the field daddr
you can enter the destination coordinates.
This is how I did it
if (UIApplication.sharedApplication().canOpenURL(NSURL(string:"comgooglemaps://")!)) {
UIApplication.sharedApplication().openURL(NSURL(string:
"comgooglemaps://?saddr=&daddr=\(place.latitude),\(place.longitude)&directionsmode=driving")!)
} else {
NSLog("Can't use comgooglemaps://");
}
}
for any further queries you can refer to this link Google Map URL Scheme
这篇关于如何打开Google地图以使用Swift显示路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!