existe-t-il un moyen de démarrer la navigation automatiquement lors du lancement de Google Maps ou < a href = "https://developer.apple.com/library/ios/featedArticles/iphoneurlscheme_reference/maplinks/maplinks.html" rel = "Noreferrer"> Apple Maps avec un schéma d'URL sur iOS? P >
Je vois plusieurs paramètres facultatifs pour les deux mais aucune pour démarrer la navigation sans entrée utilisateur. P>
3 Réponses :
Voici comment je l'ai fait pour votre référence, mais pour Apple, je n'ai pas trouvé de moyen de démarrer la navigation via URL Schéma.
+ (void)navigateToLocation:(CLLocation*)_navLocation {
if ([[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:@"comgooglemaps://"]]) {
NSString *string = [NSString stringWithFormat:@"comgooglemaps://?daddr=%f,%f&directionsmode=driving",_navLocation.coordinate.latitude,_navLocation.coordinate.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]];
} else {
NSString *string = [NSString stringWithFormat:@"http://maps.apple.com/?ll=%f,%f",_navLocation.coordinate.latitude,_navLocation.coordinate.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]];
}
}
Ouvre les cartes et les centres sur la Lat, mais ne démarre pas la navigation :(
Vous êtes correct, Google et Apple nécessitent la saisie de l'utilisateur - mais seulement pour toucher le bouton Go.
Si vous souhaitez spécifier à la fois l'emplacement de démarrage et de fin, utilisez le format suivant: p>
Apple Maps: P>
comgooglemaps-x-callback://?saddr=&daddr=<Your Location>
Soyez prudent avec la mise en place de% 20 dans la chaîne, en% devrait être %% ou utiliser l'espace que ce soit
Pour Google Maps, le paramètre URL NAV = 1 devrait démarrer la navigation. Toujours à la recherche d'un moyen de le faire avec des cartes Apple.
Swift 3 Classe d'assistance pour démarrer les cartes Apple ou 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)
}
}