How to show location in Apple Maps and Google Maps app in iOS

Issue #309

Apple Maps

1
2
3
4
let placemark = MKPlacemark(coordinate: coordinate, addressDictionary: nil)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = shop.name
mapItem.openInMaps(launchOptions: [:])

Google Maps

Since iOS 9, we need to declare LSApplicationQueriesSchemes

1
2
3
4
<key>LSApplicationQueriesSchemes</key>
<array>
<string>comgooglemaps</string>
</array>
1
2
3
4
5
6
7
8
9
10

var string = "comgooglemaps://"
string += "?q=Food"
string += "&center=\(coordinate.latitude),\(coordinate.longitude)"
string += "&zoom=15"
let googleUrl = URL(string: string)!

if UIApplication.shared.canOpenURL(URL(string: "comgooglemaps://")!) {
UIApplication.shared.open(googleUrl)
}

Comments