2012-09-04 66 views
0

我正在使用CLGeocoder将设备的当前位置进行地理编码。它在模拟器上效果很好,但总是在设备(iPhone 4和iPad 3)上出现kCLErrorNetwork错误而失败。CLGeocoder始终在设备上失败,但在模拟器中工作

的代码是非常简单的:

if (geocoder == nil) geocoder = [[CLGeocoder alloc] init]; 
[geocoder reverseGeocodeLocation:self.location completionHandler:^(NSArray *placemarks, NSError *error) { 

    if (error == nil) { 

     // Do good stuff with the placemark... 

    } else { 

     NSLog(@"unable to reverse geocode location %@ due to error: %@", self.location, error); 
    } 
}]; 

打印的错误信息是:

unable to reverse geocode location <[redacted],[redacted]> +/- 69.94m (speed -1.00 mps/course -1.00) @ 9/4/12 10:30:19 AM Eastern Daylight Time due to error: Error Domain=kCLErrorDomain Code=2 "The operation couldn’t be completed. (kCLErrorDomain error 2. 

一旦CLLocationManager提供了一个位置此方法仅调用,所以该方法总是通过一个有效的位置。

我已经在几个Wi-Fi网络和3G网络上尝试过它。它从不在设备上工作。

任何帮助将不胜感激!

+0

您应该首先检查地标是否为零,如果是,那么您可以查看错误 – Felix

+0

@ phix23恐怕地标为零,所以似乎没有问题。 –

回答

0

这可能不是问题与您的问题,但我猜设备上的网络层崩溃,并且意味着它没有连接到互联网。关闭飞机模式并为我解决问题。

相关问题