2013-02-24 2 views
1

사용자가 '길 찾기'버튼을 누른 후 내 앱에서지도 앱을 실행하려면 MKMapItem을 사용하고 있습니다. 지도 앱은 현재 위치에서 주소까지 길 찾기를 표시합니다. 하지만 내 앱으로 돌아가려면 어떻게해야합니까? 길 찾기를 더 이상보고 싶지 않으면? 아래 코드는 IBAction입니다.IOS 6에서지도 앱을 종료하는 방법 즉 앱 요청 방향으로 제어권을 되 돌리시겠습니까?

코드 :


- (IBAction)pressDirectionsButton:(id)sender { 

Class mapItemClass = [MKMapItem class]; 
if (mapItemClass && [mapItemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) 
{ 
    CLGeocoder *geocoder = [[CLGeocoder alloc] init]; 
    NSString *addressString = [NSString stringWithFormat:@"%@,%@,%@,%@,%@", 
           self.currentlySelectedTemple.houseNumber, 
           self.currentlySelectedTemple.street, 
           self.currentlySelectedTemple.city, 
           self.currentlySelectedTemple.state, 
           self.currentlySelectedTemple.country]; 
    [geocoder geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *error) { 

     //Convert CLPlacemark to an MKPlacemark 
     CLPlacemark *geocodedPlacemark = [placemarks objectAtIndex:0]; 
     MKPlacemark *placemark = [[MKPlacemark alloc] 
            initWithCoordinate:geocodedPlacemark.location.coordinate addressDictionary:geocodedPlacemark.addressDictionary]; 

     //Create a map item for geocoded address to pass to Maps app 
     MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark]; 
     [mapItem setName:geocodedPlacemark.name]; 

     //Set Directions mode to Driving 
     NSDictionary *launchOptions = @{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}; 

     //Get the "Current User Locations" MKMapItem 
     MKMapItem *currentLocationMapItem = [MKMapItem mapItemForCurrentLocation]; 

     //Pass the current location and destination map items to Maps app 
     [MKMapItem openMapsWithItems:@[currentLocationMapItem, mapItem] launchOptions:launchOptions]; 

     }]; 
    } 

    } 

답변

2

다시 응용 프로그램 (프로그래밍 방식), 더 이상 앱에 그대로 있지만,지도 앱에 갈 수있는 방법이 없습니다. openMapsWithItems:launchOptions:을 실행하면 App Delegate의 applicationdDidEnterBackground: 메서드가 호출됩니다.

현재 Mapkit을 사용하여 앱 내에 길 찾기가 포함 된지도를 삽입 할 수있는 방법이 없습니다.