我调用此方法将用户定向到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}];
}
答案 0 :(得分:0)
您应该在iOS 6及更高版本上使用MKPlacemark
。
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:[view annotation]coordinate]] addressDictionary:nil];
MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
[mapItem openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving}];