3

iPhoneSDKアプリからマップアプリを起動しようとしています。今のところ、道順を使って地図アプリを起動できますが、道順の概要が表示され、Siriと音声ナビゲーションを使用して順番に道順を示すことはありません。

現在、このコードを起動するボタンがあります...

NSString *address = viewedObject.addressFull;
NSString *url = [NSString stringWithFormat: @"http://maps.apple.com/maps?saddr=%f,%f&daddr=%@", here.latitude, here.longitude, [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
4

2 に答える 2

4

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'];
于 2012-12-15T20:58:25.457 に答える
2

上記のプログラムの回答の上に構築しました...以下のコードは、住所のNSString入力を取得し、それをジオコーディングしてから、NSString入力への音声ナビゲート方向でマップアプリを開きます。NameStringとPhoneStringは、マップアプリに配置された目印に付加されます。以下のコードは、上記のプログラムのコードなしでは不可能です。彼の答えを有用なものとしてマークしてください。

    [self.geocoder geocodeAddressString:AddressString completionHandler:^(NSArray *placemarks, NSError *error) {

        if ([placemarks count] > 0) {
            CLPlacemark *placemark = [placemarks objectAtIndex:0];
            CLLocation *location = placemark.location;
            CLLocationCoordinate2D there = location.coordinate;

            MKPlacemark *destPlace = [[MKPlacemark alloc] initWithCoordinate:there addressDictionary:nil];
            MKMapItem *destMapItem = [[MKMapItem alloc] initWithPlacemark:destPlace];
            destMapItem.name = NameString;
            destMapItem.phoneNumber = PhoneString;

            NSArray* mapItems = [[NSArray alloc] initWithObjects: destMapItem, nil];
            NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:MKLaunchOptionsDirectionsModeDriving, MKLaunchOptionsDirectionsModeKey, nil];
            [MKMapItem openMapsWithItems:mapItems launchOptions:options];
        }
    }];
于 2012-12-17T04:46:41.460 に答える