从另一个应用程序打开 Google 地图应用程序进行导航 [英] Opening Google map app for navigation from another Application

查看:48
本文介绍了从另一个应用程序打开 Google 地图应用程序进行导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用这些代码从我的应用程序打开谷歌地图应用程序

I have tried to open google map application from my app using these code

if (UIApplication.sharedApplication().canOpenURL(NSURL(string:"comgooglemaps://")!)) {
        UIApplication.sharedApplication().openURL(NSURL(string:
            "comgooglemaps://?saddr=\(fromLatitude),\(fromLongitude)&daddr=\(toLatitude),\(toLongitude)&directionsmode=driving")!)
    }else{
        showAlert()
    }

我已经在我的 iphone 中安装了谷歌地图,但这段代码总是会用到其他部分

I have installed google map in my iphone but this code always going to else part

推荐答案

启动服务(macOS 中核心服务框架的一部分)提供对启动应用程序和匹配文档类型的支持应用.

Launch Services (part of the Core Services framework in macOS) provides support for launching apps and matching document types to apps.

您应该将其包含在您的 info.plist 文件中

You should include this in your info.plist file

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>googlechromes</string>
    <string>comgooglemaps</string>
</array>

如果没有安装谷歌地图,您可以在浏览器中打开.

You can open in browser if google maps is not installed.

// if GoogleMap installed
if (UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!)) {
    UIApplication.shared.openURL(NSURL(string:
        "comgooglemaps://?saddr=\(fromLatitude),\(fromLongitude)&daddr=\(toLatitude),\(toLongitude)&directionsmode=driving")! as URL)

} else {
    // if GoogleMap App is not installed
    UIApplication.shared.openURL(NSURL(string:
                "https://www.google.co.in/maps/dir/?saddr=\(fromLatitude),\(fromLongitude)&daddr=\(toLatitude),\(toLongitude)&directionsmode=driving")! as URL)
}

这篇关于从另一个应用程序打开 Google 地图应用程序进行导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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