4

私は自分のアプリで Apple Map を使用しており、自分のビューで、ユーザーの場所からビューにある現在の場所までの運転方向を表示したいのですが、今はこれらすべてをアプリ内でのみ表示したいだけです。つまり、運転を表示できます方向はマップビューにあります。アップルマップアプリケーションを使用してみましたが、アプリケーションから呼び出した後、運転方向を取得するアップルのマップアプリケーションに移動しますが、アプリケーションに戻ることができないので、考えています現在のビュー自体で運転ルートを取得できるように、アプリケーション自体で何かを行うことができます..

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

このコードは、ネイティブアプリからアップルの地図アプリに移動しますが、アプリに直接戻ることはできません.運転方向を取得した後にアプリに戻ることができる解決策はありますか?? (webview は私には機能しませんでした。アップルのアプリに戻るボタンを追加できますか?)助けてください....どうもありがとうございました!!

または、アプリケーションでのみすべてを実行できるように、実装するためのより良いコードを提案してください。

ナビゲーション ルートと運転ルートを示すアプリ内マップが欲しい...

4

2 に答える 2

2

これは方向性を達成する方法ではなく、

iOS のすべてのバージョン、新しい Google マップ、iOS 6 のトムトム マップもカバーするサンプルを作成しました。

ここにあります:

if([[[UIDevice currentDevice] systemVersion] compare:@"6.0" options:NSNumericSearch] == NSOrderedDescending){
        //6.0 or above
        NSString *Destinationlatlong =[NSString stringWithFormat:@"%@,%@",your.latitude,your.longitude];

        NSString* addr = [NSString stringWithFormat:@"comgooglemaps://?saddr=%f,%f&daddr=%@",[AppDelegate zDelegate].location.coordinate.latitude,[AppDelegate zDelegate].location.coordinate.longitude, Destinationlatlong];
        addr=[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

        NSURL* url = [[[NSURL alloc] initWithString:addr]autorelease];
        //    NSLog(@"url %@",url);
        if ([[UIApplication sharedApplication]canOpenURL:url]) {
            [[UIApplication sharedApplication] openURL:url];
        }else{
            CLLocationCoordinate2D coords =
            CLLocationCoordinate2DMake([your.latitude doubleValue],[your.longitude doubleValue]);
            MKPlacemark *placeMark = [[MKPlacemark alloc]
                                      initWithCoordinate:coords addressDictionary:nil];


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

            [destination openInMapsWithLaunchOptions:nil];
        }
    }else{
        NSString *Destinationlatlong =[NSString stringWithFormat:@"%@,%@",your.latitude,your.longitude];
        NSString* addr = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=Current+Location&daddr=%@",Destinationlatlong];
        addr=[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

        NSURL* url = [[[NSURL alloc] initWithString:addr]autorelease];
        //    NSLog(@"url %@",url);
        if ([[UIApplication sharedApplication]canOpenURL:url]) {
            [[UIApplication sharedApplication] openURL:url];
        }else{
            UIAlertView *alert=[[[UIAlertView alloc] initWithTitle:@"Warning!" message:@"Device does not support this functionality" delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles: nil]autorelease] ;
            [alert show];
        }
    }
于 2013-02-13T12:53:07.693 に答える
1

これで始められるはずです。つまり、json で Google API から運転指示を取得し、それを解析して、MKPolyline http://iosguy.com/2012/05/22/tracing-routes-with-mapkit/を使用して独自のマップに表示します。

于 2013-02-11T13:25:11.253 に答える