UIActivityViewController中的GoogleMaps

时间:2016-09-19 13:20:06

标签: swift google-maps uiactivityviewcontroller

我正在尝试使用UIActivityViewController打开googlemaps,我搜索过并发现此代码应该可以使用

@IBAction func showRestaurantOnMap(_ sender: UIButton) {
    let url = NSURL(string: "comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic")
    let activityViewController : UIActivityViewController = UIActivityViewController(
        activityItems: [url!], applicationActivities: nil)

    activityViewController.popoverPresentationController?.sourceRect = CGRect(x: 150, y: 150, width: 0, height: 0)
    activityViewController.excludedActivityTypes = []

    self.present(activityViewController, animated: true, completion: nil)
}

但事实并非如此,我做错了什么?

更新:

    if UIApplication.shared.canOpenURL(URL(string: "comgooglemaps://")!) {
        print(1)
    }
    if UIApplication.shared.canOpenURL(URL(string: "yandexmaps://")!) {
        print(2)
    }
    if UIApplication.shared.canOpenURL(URL(string: "http://maps.apple.com/")!) {
        print(3)
    }

工作完美并返回1,2和3

0 个答案:

没有答案