1

在用户点击“方向”按钮后,我正在使用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];

       }];
    }

    }
4

1 回答 1

2

无法返回到您的应用程序(以编程方式),因为您不再在您的应用程序中,而是在地图应用程序中。执行后openMapsWithItems:launchOptions:,您的 App Delegate 的applicationdDidEnterBackground:方法将被调用。

目前无法使用 Mapkit 在您的应用程序中嵌入带有路线的地图。

于 2013-03-28T13:40:28.590 回答