1

私は iOS < 6 用にビルドされたアプリを持っていますが、それ以前はすべての機能が完全に動作していました。デバイスにインストールされている iOS を認識するスイッチを使用すると、アプリが正しいマップを開いて、ローカル位置から別の位置 (マップ上のいくつかのピン) への道順を取得します。問題は、iOS 6 より前では、アプリがネイティブ マップを開き、ルートをユーザーに表示することです。現在、デバイスが iOS 6 を使用している場合、アプリは Apple マップを開きますが、「この 2 つの位置の間で方向を取得できません」などのポップアップが表示されます。なんで?誰かがこの問題を解決するのを手伝ってくれますか?

ここでは、開示ボタンからマップに座標を渡す方法を示します。

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

    [self.navigationController pushViewController:[[UIViewController alloc] init] animated:YES];

    if (SYSTEM_VERSION_LESS_THAN(@"6.0")) {
         NSString* addr = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%1.6f,%1.6f&saddr=Posizione attuale", view.annotation.coordinate.latitude,view.annotation.coordinate.longitude];
         NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
         [[UIApplication sharedApplication] openURL:url];
    }

    else {
        NSString* addr = [NSString stringWithFormat:@"http://maps.apple.com/maps?daddr=%1.6f,%1.6f&saddr=Posizione attuale", view.annotation.coordinate.latitude,view.annotation.coordinate.longitude];
        NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        [[UIApplication sharedApplication] openURL:url];


    }
4

2 に答える 2

3

マップには URL メソッドを使用できますが ( http://maps.apple.com/...)、特定の場所を表示する場合にはあまり適していないことがわかりました。最善の策は、iOS 6 以降で MapKit オブジェクトを使用することです。

例:

CLLocationCoordinate2D location;
location.latitude = ...;
location.longtitude = ...;

MKPlacemark* placemark = [[MKPlacemark alloc] initWithCoordinate:location addressDictionary:nil];

MKMapItem* item = [[MKMapItem alloc] initWithPlacemark:placemark];
//... Any Item customizations

NSDictionary* mapLaunchOptions = ...;
[item openInMapsWithLaunchOptions:mapLaunchOptions];

これにより、Apple マップが直接開き、提供したアイテムが表示されます。

道順を処理するには、MKLaunchOptionsDirectionsModeKeylaunch オプションを使用し、次の方法で開始と終了のマップ アイテムを提供します。

[MKMapItem openMapsWithItems:mapItems launchOptions:launchOptions];
于 2012-10-21T22:06:43.163 に答える