1

我调用此方法将用户引导到 Apple Map 上。它在 iOS 6 上运行良好,但现在不能在 iOS 7 上运行。请问问题出在哪里?

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{

lat1 = [[view annotation]coordinate].latitude;
lon1 = [[view annotation]coordinate].longitude;

NSString *str = [NSString stringWithFormat:@"http://maps.apple.com/maps?saddr=%f,%f&daddr=%f,%f", lat1,lon1,lat,lon];    

NSURL *URL = [NSURL URLWithString:str];

[[UIApplication sharedApplication] openURL:URL];

}

更新

-(void)direct:(id)sender{

CLLocationCoordinate2D coordinate;
coordinate.latitude = 40.896056;
coordinate.longitude = 29.217947;

MKPlacemark *mPlacemark = [[[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil] autorelease];
MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:mPlacemark];
[mapItem openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey  : MKLaunchOptionsDirectionsModeDriving}];
}
4

1 回答 1

0

您应该MKPlacemark在 iOS 6 及更高版本上使用。

MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:[view annotation]coordinate]] addressDictionary:nil];
MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
[mapItem openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey  : MKLaunchOptionsDirectionsModeDriving}];
于 2013-09-23T08:15:43.170 回答