Swift 3 Hilfsklasse für Starten von Apple Maps oder Google Maps navigation
struct LinksHelper {
static func startNavigation(coordinate: CLLocationCoordinate2D) {
struct Links {
static let kGoogleMapsSchema = "comgooglemaps://"
static let kGoogleMaps = "\(kGoogleMapsSchema)?daddr=%f,%f&directionsmode=driving"
static let kAppleMaps = "https://maps.apple.com/?saddr=Current Location&daddr=%f,%f&z=10&t=s"
}
var path: String!
if let googleMapsSchemaUrl = URL(string:Links.kGoogleMapsSchema), UIApplication.shared.canOpenURL(googleMapsSchemaUrl) {
path = Links.kGoogleMaps
} else {
path = Links.kAppleMaps
}
guard let str = String(format: path, coordinate.latitude, coordinate.longitude).addingPercentEncoding(
withAllowedCharacters: .urlQueryAllowed) else {
return
}
guard let url = URL(string: str) else {
return
}
UIApplication.shared.openURL(url)
}
}
Öffnet den Standort der Karten und Zentren auf dem Breitengrad, startet aber nicht mit der Navigation :( – htafoya