J'ai construit une application pour les motards de Copenhague, mais j'ai quelques problèmes. L'application doit ouvrir les cartes Apple lorsque Google Maps n'est pas disponible sur le téléphone.Swift: App doit ouvrir Apple Maps lorsque Google Maps n'est pas installé
Le code ressemble à ceci
// OUTLETS!
@IBOutlet weak var googleMapsView: GMSMapView!
// VARIABLES!
var locationManager = CLLocationManager()
var M1: GMSMarker!
var M2: GMSMarker!
//Marker funtioncs
var markerFunctions: [GMSMarker: (() -> Void)]!
override func viewDidLoad() {
super.viewDidLoad()
// GET LOCATION WHILE USING APP
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
locationManager.startMonitoringSignificantLocationChanges()
initGoogleMaps()
}
// START GOOGLE MAPS!
func initGoogleMaps() {
// MARKERS
M1 = GMSMarker()
M1.position = CLLocationCoordinate2D(latitude: 55.65208178045790, longitude: 12.527047696518300)
M1.title = "Sjælør St."
M1.snippet = "Press for navigation"
M1.map = self.googleMapsView
M2 = GMSMarker()
M2.position = CLLocationCoordinate2D(latitude: 55.67530850095370, longitude: 12.583165039072400)
M2.title = "Børsen (Slotsholmsgade)"
M2.snippet = "Press for navigation"
M2.map = self.googleMapsView
// Marker functions
markerFunctions = [
M1: { UIApplication.shared.open(NSURL(string: "comgooglemaps-x-callback://" +
"?daddr=55.65208178045790,12.527047696518300&directionsmode=bicycling&zoom=17")! as URL)},
M2: { UIApplication.shared.open(NSURL(string: "comgooglemaps-x-callback://" +
"?daddr=55.67530850095370,12.583165039072400&directionsmode=bicycling&zoom=17")! as URL)},
Lorsque vous tapez sur la ligne Info-fenêtre, navigation Google Maps doit apparaître (cela fonctionne). Cependant, si l'application Google Maps n'est pas disponible, comment puis-je réécrire les "Fonctions de marqueurs" afin de les ouvrir à la place?
https://developer.apple.com/library/prerelease/content/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html? Cochez "canOpenURL()" pour savoir lequel est disponible. – Larme