从app中打开Apple Maps时更改起始位置

时间:2014-11-06 15:41:18

标签: objective-c mapkit core-location ios7.1

默认情况下,当通过MKMapItem打开Apple地图时,它使用设备的位置作为起点,但我试图允许用户通过输入正确的字段(地址,城市)来添加自己的起点,州,邮政编码)并将地址字符串传递给

CLGeocoder *geocoder = [[CLGeocoder alloc] init];
            NSString *addressString = [NSString stringWithFormat:@"%@ %@ %@ %@",
                                                               self.address.text,
                                                               self.city.text,
                                                               self.state.text,
                                                               self.zip.text];

            [geocoder geocodeAddressString:addressString
                         completionHandler:^(NSArray *placemarks, NSError *error)
            {
                CLLocationCoordinate2D addressCoordinates;

                 if (error.code == 2)
                 {
                     UIAlertView *networkConnectionAlert = [[UIAlertView alloc] initWithTitle:@"Network Error" message:@"The internet connections appears to be offline. Ensure that data is enabled or that your device is connected to a wireless connection." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                     [networkConnectionAlert show];

                     NSLog(@"Geocode failed with error: %@", error);
                     return;
                 }

                 if (placemarks && placemarks.count > 0)
                 {
                     CLPlacemark *placemark = placemarks[0];

                     // Location of address passed in
                     CLLocation *location = placemark.location;

                     // Coordinates of address passed in
                     addressCoordinates = location.coordinate;
                 }

                // Destination address dictionary values
                NSDictionary *address = @{
                                          (NSString *)kABPersonAddressStreetKey: self.address.text,
                                          (NSString *)kABPersonAddressCityKey: self.city.text,
                                          (NSString *)kABPersonAddressStateKey: self.state.text,
                                          (NSString *)kABPersonAddressZIPKey: self.zip.text
                                          };

                MKPlacemark *place = [[MKPlacemark alloc] initWithCoordinate:addressCoordinates
                                                           addressDictionary:address];

                MKMapItem *mapItem = [[MKMapItem alloc]initWithPlacemark:place];

                NSDictionary *options = @{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving};

                [mapItem openInMapsWithLaunchOptions:options];
             }];

当然,每次运行应用程序时,它都会使用设备的位置作为起点,目的地点作为输入的地址,根据上面的代码可以理解,但是没有可以调用的属性来更改起点?我知道你可以在打开实际的Apple Maps时更改起始地址/位置,所以我认为必须有一种方法,我只是做错了什么或丢失了什么。对此有任何帮助将非常感谢,谢谢。

0 个答案:

没有答案
相关问题