如何在IOS 6中退出Map App,即将控制权返回给应用程序请求路线?

时间:2013-02-24 00:23:32

标签: ios6-maps mkmapitem

在用户点按“路线”按钮后,我正在使用MKMapItem从我的应用中启动地图应用。地图应用程序显示从当前位置到地址的方向。但是如何回到我的应用程序,如果我不想再看到路线?以下是我附加到IBAction的代码。

代码:


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

       }];
    }

    }

1 个答案:

答案 0 :(得分:2)

由于您不再在应用中,而是在地图应用中,因此无法以编程方式返回您的应用。执行openMapsWithItems:launchOptions:后,将调用您的App Delegate的applicationdDidEnterBackground:方法。

目前无法使用Mapkit在您的应用中嵌入包含路线的地图。