openMapsWithItems:
iOS 6では、を使用してマップを起動する新しい方法がありMKMapItem
ます。これが私が使用するスニペットで、現在の場所から提供された座標までの徒歩または運転の道順を提供します。
// iOS 6.0+ only
MKPlacemark* destPlace = [[[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil] autorelease];
MKMapItem* destMapItem = [[[MKMapItem alloc] initWithPlacemark:destPlace] autorelease]; destMapItem.name = stationItem.title;
NSArray* mapItems = [[[NSArray alloc] initWithObjects: destMapItem, nil] autorelease];
NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:
walking ? MKLaunchOptionsDirectionsModeWalking : MKLaunchOptionsDirectionsModeDriving,
MKLaunchOptionsDirectionsModeKey, nil];
[MKMapItem openMapsWithItems:mapItems launchOptions:options];
iOS 6より前のデバイスで実行している場合でも実行する必要がある方法dirflg
で、徒歩または運転の道順をリクエストするには、URLにを含める必要があります。
// pre iOS 6 code
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f&dirflg=%c",
currentLocation.coordinate.latitude,
currentLocation.coordinate.longitude,
destination.coordinate.latitude,
destination.coordinate.longitude,
walking ? 'w' : 'd'];