Mid*_*yan 1 xcode google-maps url-scheme ios swift
我试图使用这些代码从我的应用程序打开谷歌地图应用程序
if (UIApplication.sharedApplication().canOpenURL(NSURL(string:"comgooglemaps://")!)) {
UIApplication.sharedApplication().openURL(NSURL(string:
"comgooglemaps://?saddr=\(fromLatitude),\(fromLongitude)&daddr=\(toLatitude),\(toLongitude)&directionsmode=driving")!)
}else{
showAlert()
}
Run Code Online (Sandbox Code Playgroud)
我已经在我的iphone中安装了谷歌地图,但这段代码总是转向其他部分
Launch Services(macOS中的核心服务框架的一部分)为启动应用程序和将文档类型与应用程序匹配提供支持.
您应该将此包含在您的info.plist文件中
<key>LSApplicationQueriesSchemes</key>
<array>
<string>googlechromes</string>
<string>comgooglemaps</string>
</array>
Run Code Online (Sandbox Code Playgroud)
如果未安装谷歌地图,您可以在浏览器中打开.
// 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)
}
Run Code Online (Sandbox Code Playgroud)