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