立即在iOS 6.0中打开Apple Maps并从当前位置开始路由到主页

我想在我的应用程序中创build一个链接,本质上将被标记为“带我回家”。 当按下时,我希望它打开苹果地图,从当前位置路由到家,并开始转弯导航。

我find了这个scheme,但是并没有做到我所希望的一切:

http://maps.apple.com/maps?saddr=%f,%f&daddr=%f,%f 

以下是用路线打开地图的工作代码(包括显示适用于iOS5的Google地图的选项)

 -(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]]; } } 

使用这个对我来说,它的工作精细::

 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]];