Comment serais-je capable d'ouvrir google maps lorsque j'appuie sur un button de mon application?

J'ai cette application et je veux utiliser Google Maps ou Apple Maps pour ouvrir lorsque l'user appuie sur un button dans mon application. Comment serais-je capable de faire ça? Y at-il un lien vers les maps qui ouvre l'application ou est-ce autre chose? Si vous pouvez me diriger dans la bonne direction, ce serait vraiment utile. Merci! J'ai le button mis en place ci-dessous comme ceci:

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) { for touch in (touches ) { let location = touch.locationInNode(self) let node = self.nodeAtPoint(location) if node.name == "openMaps" { //code to open google maps or apple maps.... } 

Utilisez ceci:

 if node.name == "openMaps" { let customURL = "comgooglemaps://" if UIApplication.sharedApplication().canOpenURL(NSURL(ssortingng: customURL)) { UIApplication.sharedApplication().openURL(NSURL(ssortingng: customURL)) } else { var alert = UIAlertController(title: "Error", message: "Google maps not installed", preferredStyle: UIAlertControllerStyle.Alert) var ok = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil) alert.addAction(ok) self.presentViewController(alert, animated:true, completion: nil) } } 

Vous findez plus d'informations sur le schéma d'URL google maps ici

Editer: Vous devez append une key à votre info.plist pour que cela fonctionne.

 <key>LSApplicationQueriesSchemes</key> <array> <ssortingng>googlechromes</ssortingng> <ssortingng>comgooglemaps</ssortingng> </array> 

Edit: Par Google Maps mis à jour ajouté "googlechromes" à plist ci-dessus aussi.

Au clic du button (en action) appelez la fonction "directions ()" avec le code suivant:

 func directions() { // if GoogleMap installed if (UIApplication.shared.canOpenURL(URL(ssortingng:"comgooglemaps://")!)) { UIApplication.shared.openURL(NSURL(ssortingng: "comgooglemaps://?saddr=&daddr=\(Float(event.addressLat)!),\(Float(event.addressLong)!)&directionsmode=driving")! as URL) } else { // if GoogleMap App is not installed UIApplication.shared.openURL(NSURL(ssortingng: "https://maps.google.com/?q=@\(Float(event.addressLat)!),\(Float(event.addressLong)!)")! as URL) } } 

Modifiez votre info.plist pour LSApplicationQueriesSchemes:

entrez la description de l'image ici

L'espoir aidera!