[英]How to open native GoogleMaps App & Waze App
I want to open directions driving mode in both GoogleMaps & Waze in native app. 我想在本机应用程序的GoogleMaps和Waze中打开行车路线模式。 How to do it? 怎么做?
func showActionSheet(vc: UIViewController) {
let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
actionSheet.addAction(UIAlertAction(title: "Google Maps", style: .default, handler: { (alert:UIAlertAction!) -> Void in
self.openGoogleMaps()
}))
actionSheet.addAction(UIAlertAction(title: "Waze", style: .default, handler: { (alert:UIAlertAction!) -> Void in
self.openWaze()
}))
actionSheet.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
vc.present(actionSheet, animated: true, completion: nil)
}
Currently I've implement 2 functions, but I would like to know how to open in native apps for both maps 目前,我已经实现了2个功能,但是我想知道如何在本机应用中打开两个地图
func openGoogleMaps() {
//Don't want open in URL, want to open in native googlemaps app
}
func openWaze() {
//Don't want open in URL, want to open in native Waze app
}
First check Waze or Google map apps are available or not on user's phone. 首先检查Waze或Google地图应用程序是否在用户的手机上可用。 After that, you can open Waze/Google app from your app with URL Scheeme. 之后,您可以使用URL Scheeme从您的应用程序中打开Waze / Google应用程序。
func openGoogleMaps() {
if (UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!)) { //First check Google Mpas installed on User's phone or not.
UIApplication.shared.openURL(URL(string: "comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic")!) //It will open native google maps app.
} else {
print("Can't use comgooglemaps://");
}
}
func openWaze() {
if (UIApplication.shared.canOpenURL(URL(string:"waze://")!)) { //First check Waze Mpas installed on User's phone or not.
UIApplication.shared.openURL(URL(string: "waze://")!) //It will open native wazw maps app.
} else {
print("Can't use waze://");
}
}
When compiling with iOS SDK 9.0 and later, you must update your application's property list file with the following to include Waze: 使用iOS SDK 9.0和更高版本进行编译时,必须使用以下内容更新应用程序的属性列表文件以包含Waze:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>waze</string>
</array>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.