如何打开Goog​​le地图以使用Swift显示路线 [英] How to open Google Maps to show route using Swift

查看:94
本文介绍了如何打开Goog​​le地图以使用Swift显示路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在互联网上阅读,但无法找到合理的答案。我需要在用户点击按钮显示路线时打开Goog​​le地图。开始和目的地必须自动填充。



如何在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

这篇关于如何打开Goog​​le地图以使用Swift显示路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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