4

関連するパラメーターを使用して Google マップの URL を読み込む UIWebView で、ポイント A から別のポイント B への徒歩ルートを表示する必要がある iPhone アプリに取り組んでいます。

読み込んでいる URL の例:

[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://maps.google.com/maps?saddr=55.720923,12.513428&daddr=55.745666,12.546387"]]];

以下のリンクの図のように、方向を地図として (地図上の線として)表示するには、UIWebView が必要です。

道順を表示する方法 (地図としての道順)

ただし、この URL が iPhone に読み込まれると、道順は代わりにリストとして表示されます(以下のリンクを参照)。

ルート案内の表示方法(ルート案内一覧)

道順を地図として表示するには、トップバーの地図ボタンを押す必要があります。

道順がiPhone アプリで(リストとしてではなく) 地図として直接表示されるように、Google マップの URL パラメータを設定するにはどうすればよいですか?

4

2 に答える 2

1

github から MKMapView.check nvpolylineプロジェクトを使用すると、これははるかに簡単になります。点aと点bの間に線を作成するのに役立ち、最初の問題を解決します.

2番目の問題については、このコードをプロジェクトに追加してください

NSString* apiUrlStr = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%@&destination=%@&sensor=false", saddr, daddr];
    //&alternatives=true

    NSURL* apiUrl = [NSURL URLWithString:apiUrlStr];

    NSString *apiResponse = [NSString stringWithContentsOfURL:apiUrl];

    SBJsonParser *jsonParser = [SBJsonParser new];
    NSDictionary *jsonData = (NSDictionary *) [jsonParser objectWithString:apiResponse error:nil];

    NSLog(@"apiResponse is : %@",jsonData);

    //to display route in drop down

    NSArray *routeArray = [[NSArray alloc]init];
    routeArray= [jsonData objectForKey:@"routes"];

    for(int i=0;i<[routeArray count];i++)
    {
        NSDictionary *tempDictionary = [routeArray objectAtIndex:i];
        if([tempDictionary objectForKey:@"overview_polyline"]!=nil)
        {
            NSDictionary *secTempDictionary = [tempDictionary objectForKey:@"overview_polyline"];
            if([secTempDictionary objectForKey:@"points"]!=nil)
            {
                NSString * routePoint =[secTempDictionary objectForKey:@"points"];

                [routeSetAry addObject:routePoint];

                encodedPoints = [secTempDictionary objectForKey:@"points"];
            }
            // NSLog(@"secTempDictionary is: %@", secTempDictionary);
        } 
        if([tempDictionary objectForKey:@"legs"]!=nil)
        {
            NSArray *lagArray = [[NSArray alloc]init];
            lagArray= [tempDictionary objectForKey:@"legs"];

            for(int i=0;i<[lagArray count];i++)
            {
                NSDictionary *thirdTempDictionary = [lagArray objectAtIndex:i];
                if([thirdTempDictionary objectForKey:@"steps"]!=nil)
                {
                    NSArray *stepsArray = [[NSArray alloc]init];
                    stepsArray= [thirdTempDictionary objectForKey:@"steps"];

                    for(int i=0;i<[stepsArray count];i++)
                    {
                        NSDictionary *forthTempDictionary = [stepsArray objectAtIndex:i];

                        if([forthTempDictionary objectForKey:@"html_instructions"]!=nil)
                        {
                            NSString * directionStr =[forthTempDictionary objectForKey:@"html_instructions"];

                            NSRange range;
                            while ((range = [directionStr rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound){
                                directionStr=[directionStr stringByReplacingCharactersInRange:range withString:@""];
                            }
                            [directionStrAry addObject:directionStr];
                        }

                        NSDictionary *fifthTempDictionary = [forthTempDictionary objectForKey:@"polyline"];
                        if([fifthTempDictionary objectForKey:@"points"]!=nil)
                        {
                            NSString * routePoint =[fifthTempDictionary objectForKey:@"points"];

                            [polylineSetAry addObject:routePoint];

                           // encodedPoints = [fifthTempDictionary objectForKey:@"points"];
                        }
                        NSDictionary *sixthTempDictionary =[forthTempDictionary objectForKey:@"distance"];
                        if([sixthTempDictionary objectForKey:@"text"]!=nil)
                        {
                            NSString * distanceStr =[sixthTempDictionary objectForKey:@"text"];

                            [distanceStrAry addObject:distanceStr];

                            // encodedPoints = [fifthTempDictionary objectForKey:@"points"];
                        } 
                    }
                }
            }
        }  
    }

    NSLog(@"routeSetAry is :%@",routeSetAry);
 NSLog(@"polylineSetAry is : %i",polylineSetAry.count);

これにより、方向文字列の配列が得られ、この文字列を使用してプロジェクトのどこにでも表示できます。

私のプロジェクトでは、マップの上部に表示される小さなビューを作成しました。そのビューでは、方向を 1 つずつ表示しています。

于 2013-02-04T10:21:58.963 に答える
0

よくわかりませんが、このリンクを参照する必要があります Googleは「Google Maps URL Scheme」をよく説明しています

使用できます

"comgooglemaps://?saddr=Google+Inc,+8th+Avenue,+New+York,+NY&daddr=John+F.+Kennedy+International+Airport,+Van+Wyck+Expressway,+Jamaica,+New+York&directionsmode =トランジット"

saddrdaddrdirectionmodeなどのさまざまなパラメーターがあり ます

お役に立てれば!

于 2013-10-01T05:58:48.837 に答える