iOS谷歌地图给出错误

时间:2013-12-03 08:21:24

标签: ios objective-c

在我的应用程序中,可以点击一个按钮,然后在Google地图应用程序中显示从当前位置到目的地的路线。它一直在工作,直到一些内部数据结构发生了变化,现在却没有;)

我得到的错误是:

Error Domain=kCLErrorDomain Code=8 "The operation couldn’t be completed. (kCLErrorDomain error 8.)"

我在documentation中查到了(我认为):

kCLErrorGeocodeFoundNoResult
The geocode request yielded no result.
Available in iOS 5.0 and later.
Declared in CLError.h.

目前这是我的代码:(我现在正在使用硬编码的位置进行测试):

+ (void) showRouteInMapsFromCurrentToLocation:(NSString *) location{
    Class mapItemClass = [MKMapItem class];
    if (mapItemClass && [mapItemClass   respondsToSelector:@selector(openMapsWithItems:launchOptions:)]){
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressString:@"Kardingerweg 48, Groningen"
                 completionHandler:^(NSArray *placemarks, NSError *error) {
                     if(!error){
                                                 CLPlacemark *geocodedPlacemark = [placemarks objectAtIndex:0];
                        MKPlacemark *placemark = [[MKPlacemark alloc]
                                           initWithCoordinate:geocodedPlacemark.location.coordinate
                                           addressDictionary:geocodedPlacemark.addressDictionary];

                        if(placemark && geocodedPlacemark){
                            MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
                            [mapItem setName:geocodedPlacemark.name];
                            NSDictionary *launchOptions = @{MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving};
                            MKMapItem *currentLocationMapItem = [MKMapItem mapItemForCurrentLocation];
                            [MKMapItem openMapsWithItems:@[currentLocationMapItem, mapItem] launchOptions:launchOptions];
                     }
                     }else{
                         NSLog(@"%@", [error description]);
                     }
                 }];
       }
}

2 个答案:

答案 0 :(得分:1)

错误代码8是“ kCLErrorGeocodeFoundNoResult ”,因此我怀疑您正在搜索没有结果的内容,

您正在搜索'Kardingerweg 48,Groningen'它也没有在苹果地图中搜索,尝试使用不同的位置。'Kardingerweg,Groningen'

答案 1 :(得分:0)

感谢Viruss mca的回答,我现在有了正确的形式:

Kardingerweg 48, NL-2165 VS Groningen