0

Maps API を使用する iOS アプリケーションで複数のルートを表示する必要があります。単一のルートを描画することはできますが、複数のルートを描画するにはどうすればよいですか?

Google方向APIを使用して単一のルートを取得しています

http://maps.googleapis.com/maps/api/directions/json?origin=28.6353080000,77.2249600000&destination=28.5355161000,77.3910265000&mode=walking&sensor=false

また、iPhone の iOS 5 ネイティブ マップ アプリケーションでは、Route1 と Route 2 という 2 つのポップアップが表示され、ユーザーが選択したルートに触れると強調表示されます。

4

2 に答える 2

0

alternatives (オプション) は、true に設定されている場合、ルート案内サービスが応答で複数の代替ルートを提供できることを指定します。代替ルートを提供すると、サーバーからの応答時間が長くなる可能性があることに注意してください。

Google Directions APIから

クエリリンクにalternatives=trueを追加する必要があります

参照: 2 つの場所の間のルートの数を見つける

于 2012-10-11T04:32:50.567 に答える
0

コードはこちら

このコードを書く

#pragma mark - MapView Delegate

//-----------------------------------------------------------------------

    - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {

        //   [self.mapView removeAnnotation:self.annotation];

            NSString *baseUrl = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%f,%f&destination=%f,%f&sensor=true", self.mapView.userLocation.location.coordinate.latitude, self.mapView.userLocation.location.coordinate.longitude, [[self.dictData valueForKey:@"latitude"]doubleValue],[[self.dictData valueForKey:@"longitude"]doubleValue]];

            NSURL *url = [NSURL URLWithString:[baseUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

            NSURLRequest *request = [NSURLRequest requestWithURL:url];

            [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

                NSError *error = nil;
                NSDictionary *result = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];

                NSArray *routes = [result objectForKey:@"routes"];

                NSDictionary *firstRoute = [routes objectAtIndex:0];

                NSDictionary *leg = [[firstRoute objectForKey:@"legs"] objectAtIndex:0];

                NSDictionary *end_location = [leg objectForKey:@"end_location"];

                double latitude = [[end_location objectForKey:@"lat"] doubleValue];
                double longitude = [[end_location objectForKey:@"lng"] doubleValue];

                CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);

                MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
                point.coordinate = coordinate;
                point.title = [leg objectForKey:@"end_address"];
                point.subtitle = @"Event Destinations !!!";

                [self.mapView addAnnotation:point];

                NSArray *steps = [leg objectForKey:@"steps"];

                int stepIndex = 0;

                CLLocationCoordinate2D stepCoordinates[1 + [steps count] + 1];

                stepCoordinates[stepIndex] = userLocation.coordinate;

                for (NSDictionary *step in steps) {

                    NSDictionary *start_location = [step objectForKey:@"start_location"];
                    stepCoordinates[++stepIndex] = [self coordinateWithLocation:start_location];

                    if ([steps count] == stepIndex){
                        NSDictionary *end_location = [step objectForKey:@"end_location"];
                        stepCoordinates[++stepIndex] = [self coordinateWithLocation:end_location];
                    }
                }

                MKPolyline *polyLine = [MKPolyline polylineWithCoordinates:stepCoordinates count:1 + stepIndex];
                [self.mapView addOverlay:polyLine];

            }];
    }

#pragma mark - Custom Methods

//-----------------------------------------------------------------------

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {
    MKPolylineView *polylineView = [[MKPolylineView alloc] initWithPolyline:overlay];
    polylineView.strokeColor = [UIColor colorWithRed:204/255. green:45/255. blue:70/255. alpha:1.0];
    polylineView.lineWidth = 10.0;

    return polylineView;
}
于 2015-04-30T12:21:18.763 に答える