我有这个代码打开具有特定位置的Google Maps App并且它正在运行但我需要的是在该位置放置一个引脚,是否可能?
if (UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!)) {
UIApplication.shared.openURL(URL(string:
"comgooglemaps://?center=\(self.location.coordinate.latitude),\(self.location.coordinate.longitude)&zoom=14&views=traffic")!)
} else {
print("Can't use comgooglemaps://");
}
怎么做?
q:搜索的查询字符串。
它在给定坐标中创建标记。试试这个
if (UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!)) {
UIApplication.shared.open(URL(string:"comgooglemaps://?center=\(self.location.coordinate.latitude),\(self.location.coordinate.longitude)&zoom=14&views=traffic&q=\(self.location.coordinate.latitude),\(self.location.coordinate.longitude)")!, options: [:], completionHandler: nil)
} else {
print("Can't use comgooglemaps://")
}
}
首先打开qazxsw poi作为源代码(右键单击文件Info.plis,然后选择源代码)并添加:
Info.plist
接下来可以更轻松地打开Google地图,创建如下功能:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>googlechromes</string>
<string>comgooglemaps</string>
</array>
每当您想要使用给定坐标打开Google地图时,只需调用func openGoogleMaps() {
if (UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!)) {
UIApplication.shared.openURL(URL(string:
"comgooglemaps://?center=\(myLatitude),\(myLongitude)&zoom=14&views=traffic")!)
} else {
print("Can't use comgooglemaps://")
}
}
函数即可。
有关更多信息,请查看openGoogleMaps()
和Maps URLs
Maps SDK for iOS
如果已安装,请使用此代码在谷歌地图中打开,否则在默认的苹果地图中打开。
Swift 3,iOS 10
if UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!) {
UIApplication.shared.open(URL(string: "comgooglemaps://?center=\(self.latitude),\(self.longitude)")!, options: [:], completionHandler: nil)
} else {
print("Opening in Apple Map")
let coordinate = CLLocationCoordinate2DMake(self.latitude, self.longitude)
let region = MKCoordinateRegionMake(coordinate, MKCoordinateSpanMake(0.01, 0.02))
let placemark = MKPlacemark(coordinate: coordinate, addressDictionary: nil)
let mapItem = MKMapItem(placemark: placemark)
let options = [
MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: region.center),
MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: region.span)]
mapItem.name = theLocationName
mapItem.openInMaps(launchOptions: options)
}
你可以用这个:
let lat = 0.0
let lon = 0.0
if UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!) {
UIApplication.shared.open(URL(string: "comgooglemaps://?center=\(lat),\(lon)&zoom=14&views=traffic&q=loc:\(lat),\(lon)")!, options: [:], completionHandler: nil)
} else {
print("Can't use comgooglemaps://")
UIApplication.shared.open(URL(string: "http://maps.google.com/maps?q=loc:\(lat),\(lon)&zoom=14&views=traffic")!, options: [:], completionHandler: nil)
}
您应该在info.Plist文件中添加此行
if (UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!)) {
UIApplication.shared.openURL(URL(string:"comgooglemaps://?center=\(self.location.coordinate.latitude),\(self.location.coordinate.longitude)&zoom=14&views=traffic&q=\(self.location.coordinate.latitude),\(self.location.coordinate.longitude)")!)
} else {
print("Can't use comgooglemaps://")
}
代码在这里:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>googlechromes</string>
<string>comgooglemaps</string>
</array>