简体   繁体   English

如何使用Google回调URL方案快速返回到您的应用程序?

[英]How to return to your app using google callback url scheme in swift?

I am using the Gooogle Url Scheme to show the directions with the press of a button in swift. 我正在使用Gooogle Url计划快速按一下按钮来显示路线。 How can i use the url callback scheme to get back to my app, after i have opened the native google maps app. 打开本机google maps应用程序后,如何使用url回调方案返回我的应用程序。 I am using the below code 我正在使用以下代码

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://");
        }
    }

I have tried referring to this link Google Map Url Scheme if anyone knows how to do it, pls answer with a sample swift code 我曾尝试参考此链接Google Map Url Scheme(如果有人知道怎么做),请提供示例快速代码作为答案

You can use the OpenInGoogleMaps component provided by Google Maps. 您可以使用Google Maps提供的OpenInGoogleMaps组件。 It even lets you encode a redirect URL to your App, which is displayed on top of the directions in the Google Maps application. 它甚至可以让您对指向应用程序的重定向URL进行编码,该URL显示在Google Maps应用程序的指示上方。

This is what the code looks like in Swift: 这是Swift中的代码:

var place: CLLocationCoordinate2D

var definition = GoogleDirectionsDefinition()
definition.destinationPoint = GoogleDirectionsWaypoint(location: place)
definition.travelMode = GoogleMapsTravelMode.Driving

OpenInGoogleMapsController.sharedInstance().openDirections(definition)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM