2012-09-14 5 views
8

이상한 문제가 있습니다. 내 앱이 iOS의지도 (5.1과 6)를 호출 할 수 있어야합니다. iOS6에서는 제대로 작동하지만 iOS5.1에서는 정상적으로 작동하지 않습니다. iOS6의지도가 호출되고 saddr에서 daddr까지의 경로가 추적되지만 iOS5에있을 때지도 앱이 호출되지만 daddr에는 하나의 핀만 있습니다. 어떤 알려지지 않은 이유로 초기 좌표 (saddr)가 표시되지 않고 방향이 추적되지 않습니다. 나는 변화를에가 "http://maps.google.com/something는"하지만 사파리 대신지도 앱에 내장를 호출하는 URL을 시도앱 내부에서 길 찾기를 위해지도를 호출하세요 - 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]; 

:

여기 내 코드입니다. 변수가 URL에 제대로 전달되고 있음을 알았습니다.

아이디어가 있으십니까?

미리 감사드립니다.

+0

시작 주소가 다른 질문의 현재 위치라는 점을 제외하고는 사실상 동일한 질문입니다 (http://stackoverflow.com/q/576768/119114).). – Nate

답변

35

나는 비슷한 문제가있어서 Google Maps 애플리케이션이 삭제되었다는 사실을 처리하기 위해 일부 조건부 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]; 

에서 도보 경로를 얻으려면 :

  1. 아이폰 OS 6지도를 위해 - 당신은 구글지도를 위해 MKLaunchOptionsDirectionsModeWalking 대신
  2. MKLaunchOptionsDirectionsModeDriving의를 설정할 수 있습니다 - URL에 &dirflg=w를 추가합니다.

iOS6에서 openInMapsWithLaunchOptions를 사용하는 것이지도 애플리케이션의 응답 방식을 완벽하게 제어 할 수 있으므로 더 좋다고 생각합니다.

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]]; 
} 

참고가 #import <AddressBook/AddressBook.h>를 추가도 AddressBook.framework에 연결하고해야합니다 : 모두 지도 핀에 제목을 좌표로

+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

당신은지도 앱을 실행 MKPlacemarkMKMapItem을 사용할 수 있습니다 귀하의 코드 어딘가에 kABPersonAddressStreetKey 상수를 사용하십시오.

관련 문제