Apri le mappe di mele e la rotta inizia dalla posizione corrente a casa immediatamente in iOS 6.0
Domanda
Voglio creare un collegamento nella mia applicazione che essenzialmente sarà etichettato "portami a casa".Quando viene premuto, lo voglio aprire le mappe di Apple, itinerario dalla posizione corrente a casa e iniziare a girare la navigazione Turn.
Ho trovato questo schema, ma non fa tutto ciò che speravo in:
http://maps.apple.com/maps?saddr=%f,%f&daddr=%f,%f
. Soluzione
Ecco un codice funzionante per aprire mappe con rotte (inclusa l'opzione per mostrare Google Maps per iOS5)
-(IBAction)showMapApp:(id)sender
{
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(self.location.latitude,self.location.longitude);
//create MKMapItem out of coordinates
MKPlacemark* placeMark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil];
MKMapItem* destination = [[MKMapItem alloc] initWithPlacemark:placeMark];
if([destination respondsToSelector:@selector(openInMapsWithLaunchOptions:)])
{
//using iOS6 native maps app
if(_mode == 1)
{
[destination openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeWalking}];
}
if(_mode == 2)
{
[destination openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}];
}
if(_mode == 3)
{
[destination openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}];
}
} else{
//using iOS 5 which has the Google Maps application
NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=Current+Location&daddr=%f,%f", self.location.latitude, self.location.longitude];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
}
}
. Altri suggerimenti
Usa questo per me è il suo funzionamento fine ::
NSString* url = [NSString stringWithFormat: @"http://maps.apple.com/maps?saddr=44.521358,11.374080&daddr=44.518640,11.362665"];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
. Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow