2

Xcode 4.3.3、iOS 5 で開発し、Mapkit ライブラリを使用しています。アプリは Google マップに現在地を表示し、目的地の住所を取得して、最終的にその 2 点間の最短経路を描画する必要があります。

このチュートリアルを使用してアプリを実装しましたが、現在の場所がわかりました: http://blog.objectgraph.com/index.php/2009/04/02/iphone-sdk-30-playing-with-map-kit/

ルーティングを探しましたが、リソースが見つかりませんでした。現在地と目的地の間の最短経路を描く方法を教えてください。

ありがとう!

4

4 に答える 4

4

これを試すことができますが、これは ios 6 でのみ機能します。

 Class itemClass = [MKMapItem class];
        if (itemClass && [itemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) {

            CLGeocoder *geocoder = [[CLGeocoder alloc] init];
            CLLocation *newLocation = [[CLLocation alloc]initWithLatitude:getLatitude
                                                                longitude:getLongitude];

            [geocoder reverseGeocodeLocation:newLocation
                           completionHandler:^(NSArray *placemarks, NSError *error) {

                               MKPlacemark *placeMark = [[MKPlacemark alloc] initWithPlacemark:[placemarks objectAtIndex:0]];

                               MKMapItem *mapItem = [[MKMapItem alloc]initWithPlacemark:placeMark];

                               MKMapItem *mapItem2 = [MKMapItem mapItemForCurrentLocation];

                               NSArray *mapItems = @[mapItem, mapItem2];

                               NSDictionary *options = @{
                           MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving,
                           MKLaunchOptionsMapTypeKey:
                               [NSNumber numberWithInteger:MKMapTypeStandard],
                           MKLaunchOptionsShowsTrafficKey:@YES
                               };

                               [MKMapItem openMapsWithItems:mapItems launchOptions:options];

                           }         ];
        }
        else
        {
            UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Failed to Get Your Location"delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [errorAlert show];

        }
    }
于 2013-01-04T08:27:34.230 に答える
2

マップキットとルートをグーグルで検索しましたか?

これを見つけることができます: http://inlight.com.au/posts/mapkit Google マップを使用して応答をデコードし、ポイントを抽出してルートを取得する方法を説明しています。

商用キットもあります: http://mtdirectionsk.it/

于 2012-07-05T12:26:20.427 に答える
0

iOS MapKit は、Apps as a Service のルーティング情報を提供しません。代わりに、サードパーティのメカニズムから経路情報を取得するか、自分で経路を構築するかのいずれかを選択できます (基礎となる道路データがなければ、基本的に不可能です)。

独自のアプリで経路情報を提供する必要がある場合は、代替の地図システムとしてCloudMadeを検討するか、ナビゲーションに Apple の地図を利用したい場合は、地図を呼び出して場所への経路を指定することを検討してください。

ナビゲーションのためにマップ アプリを呼び出したい場合は、基本的に、ソースと目的地の場所を含む URL を開く必要があります。次に例を示します。

    CLLocationManager *manager = [[[CLLocationManager alloc] init] autorelease];
    CLLocationCoordinate2D currentLocation = [manager location].coordinate;
    NSString *from = [NSString stringWithFormat: @"%f,%f", 
                      currentLocation.latitude, currentLocation.longitude];
    // used to be able to (3.2 iPad) "Current+Location", now we have to send: lat,long
    NSString *encodedAddress = [address stringByAddingPercentEscapesUsingEncoding:
                                 NSUTF8StringEncoding];
    NSString *url = [NSString stringWithFormat:
                     @"http://maps.google.com/maps?saddr=%@&daddr=%@", from, encodedAddress];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
于 2012-07-05T11:07:59.300 に答える
0
Below ans work for all ios:
   NSString *deviceVersion   = [[UIDevice currentDevice] systemVersion];
    NSLog(@"My Device version is :%@ ",deviceVersion);


    //*********  For ios 6 supporting devices  *********
    if ([deviceVersion isEqualToString:@"6.0"])
    {

        Class itemClass = [MKMapItem class];
        if (itemClass && [itemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) {

            CLGeocoder *geocoder = [[CLGeocoder alloc] init];
            CLLocation *newLocation = [[CLLocation alloc]initWithLatitude:getLatitude
                                                                longitude:getLongitude];

            [geocoder reverseGeocodeLocation:newLocation
                           completionHandler:^(NSArray *placemarks, NSError *error) {

                               MKPlacemark *placeMark = [[MKPlacemark alloc] initWithPlacemark:[placemarks objectAtIndex:0]];

                               MKMapItem *mapItem = [[MKMapItem alloc]initWithPlacemark:placeMark];

                               MKMapItem *mapItem2 = [MKMapItem mapItemForCurrentLocation];

                               NSArray *mapItems = @[mapItem, mapItem2];

                               NSDictionary *options = @{
                           MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving,
                           MKLaunchOptionsMapTypeKey:
                               [NSNumber numberWithInteger:MKMapTypeStandard],
                           MKLaunchOptionsShowsTrafficKey:@YES
                               };

                               [MKMapItem openMapsWithItems:mapItems launchOptions:options];

                           }         ];
        }
        else
        {
            UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Failed to Get Your Location"delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [errorAlert show];

        }
    }
    //*********  For other ios supporting devices  *********
    else {

        MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
        region.center.latitude = getLatitude;
        region.center.longitude = getLongitude;

        MKCoordinateRegion currentRegion = { {0.0, 0.0 }, { 0.0, 0.0 } };
        currentRegion.center.latitude = currentLatitude;
        currentRegion.center.longitude = currentLongitude;

        region.span.longitudeDelta = 4.0f;
        region.span.latitudeDelta = 4.0f;
        currentRegion.span.longitudeDelta = 4.0f;
        currentRegion.span.latitudeDelta = 4.0f;

        CLLocationCoordinate2D start = { currentRegion.center.latitude, currentRegion.center.longitude };
        CLLocationCoordinate2D destination = { region.center.latitude, region.center.longitude };

        NSString *googleMapsURLString = [NSString stringWithFormat:@"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f",start.latitude, start.longitude, destination.latitude, destination.longitude];

        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapsURLString]];

    }

}
于 2013-01-04T08:34:09.993 に答える