2012-09-14 4 views
8

これは奇妙な問題です:私のアプリは、iOSの組み込みの地図(5.1と6の両方)を呼び出すことができます。 iOS6ではうまく動作するが、iOS5.1ではうまく動作しないことが分かる。 iOS6の地図が呼び出され、saddrからdaddrへの道順がトレースされますが、iOS5に入ると地図アプリが呼び出されますが、1つのピンだけがdaddrに配置されます。未知の理由により、初期座標(saddr)は表示されず、方向はトレースされません。ここでアプリ内からの案内のためのマップを呼び出す - iOS5 iOS6

私のコードです:

addr = [NSString stringWithFormat: @"maps://saddr=%f,%f&daddr=%f,%f", newLocation.coordinate.latitude, newLocation.coordinate.longitude, oldLatitude, oldLongitude]; 
NSURL *url = [NSURL URLWithString:addr]; 
[[UIApplication sharedApplication] openURL:url]; 

私は「http://maps.google.com/something」に変更URLを試してみましたが、それは地図アプリで構築された代わりのサファリを呼び出します。私は、変数がURLに正しく渡されていることに気付きました。

アイデア?

ありがとうございます!

+0

先頭アドレスが他の質問の現在の場所であることを除いて、実質的に同じ質問[この古いものへ](http://stackoverflow.com/q/576768/119114) )。 – Nate

答えて

35

私も同様の問題がありました.Googleマップアプリケーションが削除されたという事実に対処するために、条件付きOSコードを作成する必要がありました。新しいMKMapItem Reference

//first create latitude longitude object 
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude,longitude); 

//create MKMapItem out of coordinates 
MKPlacemark* placeMark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil]; 
MKMapItem* destination = [[MKMapItem alloc] initWithPlacemark:placeMark]; 

if([destination respondsToSelector:@selector(openInMapsWithLaunchOptions:)]) 
{ 
    //using iOS6 native maps app 
    [destination openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}];   
} 
else 
{ 
    //using iOS 5 which has the Google Maps application 
    NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=Current+Location&daddr=%f,%f", latitude, longitude]; 
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]]; 
} 

[placeMark release]; 
[destination release]; 

方向を歩い取得元:iOSの6のマップについて

  1. を - あなたは、Googleマップの場合MKLaunchOptionsDirectionsModeWalking代わりのMKLaunchOptionsDirectionsModeDriving
  2. を設定することができます - URLに&dirflg=wを追加します。

iOS6でopenInMapsWithLaunchOptionsを使用する方がよいでしょう。マップアプリケーションがどのように応答するかを完全に制御できるからです。

+1

助けてくれてありがとう!私はあなたの助言に従って、openInMapsWithLaunchOptionsを使用し、それは完全に働いた。私が使用した唯一のトリックは、NSString内のパラメータとして現在の場所を渡すことでした* url = [NSString stringWithFormat:@ "http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f" 、currentLatitude、currentLongitude、緯度、経度];私はCurrent + Location Sintaxを動作させることができなかったからです。おそらくiOS 5.1.1でサンドボックスに関することがあるかもしれません。 – lsp

+0

@lsp、 'Current + Location'の使用に関する問題は、私の答え[これと非常に似た古い質問](http://stackoverflow.com/a/964131/119114)とそれに対するコメントで述べられています。 – Nate

+0

マップビューで全画面を表示したくない場合は、 画面の半分しか表示できません。 – Arun

0

あなたはAマップピンにタイトルを座標の両方でマップのアプリを起動するMKPlacemarkMKMapItemを使用することができます:あなたはAddressBook.frameworkにリンクしても#import <AddressBook/AddressBook.h>を追加する必要があります

NSString *pinTitle; 
CLLocationCoordinate2D coordinate; 

MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:@{(id)kABPersonAddressStreetKey: pinTitle}]; 
MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark]; 

if ([mapItem respondsToSelector:@selector(openInMapsWithLaunchOptions:)]) 
{ 
    [mapItem openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving}]; 
} 
else 
{ 
    // Google Maps fallback 
    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%f,%f&saddr=Current+Location", locationItem.coordinate.latitude, locationItem.coordinate.longitude]; 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]]; 
} 

注意をあなたのコードのどこかでkABPersonAddressStreetKey定数を使用してください。

関連する問題