2012-10-20 5 views
1

iOS 용으로 빌드 된 앱은 < 6이며 모든 기능이 완벽하게 작동합니다. 이제는 기기에 설치된 iOS를 인식하는 스위치를 사용한 다음 내 앱이 올바른지도를 열어 로컬 위치에서 다른 위치로 길 찾기를 가져옵니다 (지도의 일부 핀). 문제는 iOS 6 이전에 앱이 기본지도를 열고 사용자에게 경로를 표시한다는 것입니다. 이제 기기가 iOS 6을 사용하는 경우 앱은 Apple지도를 열지 만 "이 두 위치간에 방향을 잡을 수 없음"과 같은 팝업이 표시됩니다. 왜? 누군가이 문제를 해결하도록 도와 줄 수 있습니까? 특정 위치를 제시 할 때새로운 Apple지도에서 iOS 6의 길 찾기를 받으려면 어떻게해야합니까?

당신이지도의 URL 방식 ( http://maps.apple.com/...)를 사용하는 동안, 내가 찾은
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { 

    [self.navigationController pushViewController:[[UIViewController alloc] init] animated:YES]; 

    if (SYSTEM_VERSION_LESS_THAN(@"6.0")) { 
     NSString* addr = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%1.6f,%1.6f&saddr=Posizione attuale", view.annotation.coordinate.latitude,view.annotation.coordinate.longitude]; 
     NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 
     [[UIApplication sharedApplication] openURL:url]; 
    } 

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


    } 

답변

3

가 큰되지 : 나는이 공개 버튼에서지도 좌표를 건네 방법은 다음과

. 가장 좋은 방법은 iOS 6 이상에서 MapKit 객체를 사용하는 것입니다.

예 :

CLLocationCoordinate2D location; 
location.latitude = ...; 
location.longtitude = ...; 

MKPlacemark* placemark = [[MKPlacemark alloc] initWithCoordinate:location addressDictionary:nil]; 

MKMapItem* item = [[MKMapItem alloc] initWithPlacemark:placemark]; 
//... Any Item customizations 

NSDictionary* mapLaunchOptions = ...; 
[item openInMapsWithLaunchOptions:mapLaunchOptions]; 

이것은 귀하가 제공 한 항목과 직접 애플지도가 열립니다. MKLaunchOptionsDirectionsModeKey 실행 옵션을 사용하여 방향을 처리하고,를 통해 시작과 끝지도 항목을 제공하기 위해

: 방향을 제공 할 때

[MKMapItem openMapsWithItems:mapItems launchOptions:launchOptions]; 
+0

@AlessandroBava 귀하의 필요에 맞는 것이라면 그 대답을 수락 할 수 있습니까? 고마워요 – WDUK

+0

Apple docs에 따라 2 곳 사이의 경로 만 지원합니다. 따라서 현재는 여러 위치에서 최적의 웨이 포인트가있는 Google Maps API 대신 사용할 수있는 대안이 없습니다. 따라서 유일한 방법은 Google지도를 표시하거나 열어 보는 것입니다. – Centurion

0

그냥 다른 대답을 명확히하기 위해, 두 가지 옵션이 있습니다 : 운전 또는 걷기. 각 방법을 수행하는 방법은 다음과 같습니다.

MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude) addressDictionary:nil]; 
MKMapItem *destination = [[MKMapItem alloc] initWithPlacemark:placemark]; 

//This is for driving 
[MKMapItem openMapsWithItems:@[destination] launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving}]; 

//This is for walking 
[MKMapItem openMapsWithItems:@[destination] launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeWalking}]; 

자세한 정보는 Apple's docs over here에서 확인할 수 있습니다.

관련 문제