我正在使用此代码在Swift中打开Google地图,但它无效。
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://”
任何人都可以告诉我这是什么问题吗?
修改
info.plist文件
<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>
EDIT2
let url1:NSURL = NSURL(string:"comgooglemaps://")!;
let url2:NSURL = NSURL(string:"comgooglemaps://?saddr=&daddr=\(self.selectedItem.latitude),\(self.selectedItem.longitude)&directionsmode=driving")!;
let url3:NSURL = NSURL(string:"https://www.google.com/maps?saddr=&daddr=\(self.selectedItem.latitude),\(self.selectedItem.longitude)&directionsmode=driving")!;
if (UIApplication.sharedApplication().canOpenURL(url1))
{
UIApplication.sharedApplication().openURL(url2)
} else {
UIApplication.sharedApplication().openURL(url3)
}