Ios 在iphone中打开谷歌地图不工作
我正在使用此代码在Swift中打开谷歌地图,但它不起作用Ios 在iphone中打开谷歌地图不工作,ios,swift,google-maps,Ios,Swift,Google Maps,我正在使用此代码在Swift中打开谷歌地图,但它不起作用 if (UIApplication.sharedApplication().canOpenURL(NSURL(string:"comgooglemaps://")!)) { UIApplication.sharedApplication().openURL(NSURL(string: "comgooglemaps://?center=40.765819,-73.975866&zoom=14&view
if (UIApplication.sharedApplication().canOpenURL(NSURL(string:"comgooglemaps://")!)) {
UIApplication.sharedApplication().openURL(NSURL(string:
"comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic")!)
} else {
print("Can't use comgooglemaps://");
}
它总是显示消息“不能使用comgooglemaps://”
- 我已经将谷歌地图添加到plist文件中
- 我已经多次重新启动Xcode
- 我重启了笔记本电脑
- 我已经在模拟器和真实设备上试过了
<key>LSApplicationQueriesSchemes</key>
<array>
<string>comgooglemaps</string>
<string>googlechromes</string>
<string>googlephotos</string>
<string>telprompt</string>
<string>tel</string>
<string>http</string>
<string>https</string>
</array>
试试这个
private var latitude = 30.7333
private var longitude = 76.7794
/// Open Maps Action
@IBAction func openMapsAction(_ sender: Any) {
self.openGoogleMaps()
}
//MARK: Open Google maps
func openGoogleMaps(){
// Open in Google Maps
if (UIApplication.shared.canOpenURL(NSURL(string:"comgooglemaps://")! as URL))
{
/// Driving google map
UIApplication.shared.open(URL.init(string: "comgooglemaps://?saddr=&daddr=\(self.latitude),\(self.longitude)&directionsmode=driving")!, options: [:], completionHandler: nil)
}
else
{
print("Can't use Google Maps");
}
}
需要按键
<key>LSApplicationQueriesSchemes</key>
<array>
<string>googlechromes</string>
<string>comgooglemaps</string>
</array>
LSApplicationQueriesSchemes
哪个版本的swift?显示您添加谷歌地图的Info.plist的相关部分。当然,这在模拟器中永远不会起作用,只有在安装了谷歌地图应用程序的真实iOS设备上才能起作用。@rmaddy请检查编辑,您是否在真实设备上安装了谷歌地图应用程序?请解释这个答案有什么帮助。您已为LSApplicationQueriesSchemes
发布了相同的代码和相同的相关条目。请阅读评论。OP无法使用他们在问题中发布的内容运行谷歌地图的唯一原因是他们没有安装谷歌地图应用程序。
<key>LSApplicationQueriesSchemes</key>
<array>
<string>googlechromes</string>
<string>comgooglemaps</string>
</array>