【问题标题】:How to open native GoogleMaps App & Waze App如何打开原生谷歌地图应用和位智应用
【发布时间】:2018-04-29 11:16:15
【问题描述】:

我想在本机应用程序的 GoogleMaps 和 Waze 中打开路线驾驶模式。怎么做?

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)
}

目前我已经实现了 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
}

【问题讨论】:

    标签: ios google-maps swift3 waze


    【解决方案1】:

    首先检查 Waze 或 Google 地图应用在用户手机上是否可用。 之后,您可以使用 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://");
       }
    }
    

    使用 iOS SDK 9.0 及更高版本进行编译时,您必须使用以下内容更新应用程序的属性列表文件以包含 Waze:

    <key>LSApplicationQueriesSchemes</key>
    <array>
      <string>waze</string>
    </array>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-22
      • 2017-07-25
      • 2012-09-10
      • 1970-01-01
      • 1970-01-01
      • 2020-02-20
      • 1970-01-01
      • 2013-08-09
      相关资源
      最近更新 更多