'How to open google map links on apple map in wkwebview Swift?
I have an application and i am working with WKWebView. In WkWebView i have "get directions" links. When i press the "get directions" link, it must open a map. But nothing opens. I can get links so my links are like this, "maps://maps.google.com/maps?daddr=1234567,1234567&ll=". How can i open apple maps with this links?
func openMaps (latitude: CLLocationDegrees, longitude: CLLocationDegrees) {
let googleMapsInstalled = UIApplication.shared.canOpenURL(URL(string: "comgooglemaps://")!)
if googleMapsInstalled {
UIApplication.shared.open(URL(string: "comgooglemaps-x-callback://" +
"?daddr=\(latitude),\(longitude)&=ll=")!)
} else {
let coordinates = CLLocationCoordinate2DMake(latitude, longitude)
let placemark = MKPlacemark(coordinate: coordinates, addressDictionary: nil)
let mapItem = MKMapItem(placemark: placemark)
mapItem.openInMaps(launchOptions: nil)
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|