MKErrorDomain错误4 iPhone [英] MKErrorDomain error 4 iPhone

查看:220
本文介绍了MKErrorDomain错误4 iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行我正在构建的gps应用程序时,我会随机获取此信息。它不会每次都发生,并且传入的坐标始终有效(我会记录它们)。这些地方有文件吗?

I keep getting this randomly when I run my gps app I'm building. It doesn't happen everytime, and the coordinates passed in are always valid (i nslog them). Is there documentation for these somewhere?

编辑:

CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(locManager.location.coordinate.latitude, locManager.location.coordinate.longitude);
geocoder1 = [[MKReverseGeocoder alloc] initWithCoordinate:coord];
geocoder1.delegate = self;
[geocoder1 start];

然后大约一半时间返回错误。如果出现错误,我尝试释放并重新分配地理编码器,但这没有帮助。唯一能做的就是重新启动应用程序。

and then about half the time it returns an error. I tried releasing and re-assigning the geocoder if there was an error, but that didn't help. Only thing that did was restarting the app.

推荐答案

我一直在反复出现这个错误,并且无法弄清楚如何使它停止;但是我终于找到了一个关于整个问题的最终结果,它运作得很好,只需要做一些工作:不要使用Apple的 MKReverseGeocoder - 相反,直接致电 Google的反向地理编码API (这显然是相同的服务在幕后做 MKReverseGeocoder 。您可以返回JSON或XML(您的首选项),然后您必须解析,但这不是太难。

I've been hitting this error repeatedly, and was unable to figure out how to make it stop; but I finally found an end-run around the whole issue that works quite well, and only takes a little more work: Don't use Apple's MKReverseGeocoder at all -- instead, directly call Google's reverse-geocoding API (this is apparently the same service that MKReverseGeocoder does behind the scenes). You can get back either JSON or XML (your preference), which you will then have to parse, but that isn't too hard.

例如,因为我的应用程序正在使用 ASIHTTPRequest ,这就是它的样子(尽管这也很容易用Apple的原生API,如 NSURLConnection ):

For example, since my app is using ASIHTTPRequest, this is what it looks like (although this would also be easy to do with do with Apple's native APIs such as NSURLConnection):

#pragma mark -
#pragma mark CLLocationManagerDelegate

- (void)locationManager:(CLLocationManager *)manager 
    didUpdateToLocation:(CLLocation *)newLocation 
           fromLocation:(CLLocation *)oldLocation
{
    // Be careful: My code is passing sensor=true, because I got the lat/long
    // from the iPhone's location services, but if you are passing in a lat/long
    // that was obtained by some other means, you must pass sensor=false.
    NSString* urlStr = [NSString stringWithFormat:
      @"http://maps.googleapis.com/maps/api/geocode/xml?latlng=%f,%f&sensor=true",
      newLocation.coordinate.latitude, newLocation.coordinate.longitude];
    NSURL* url = [NSURL URLWithString:urlStr];
    self.reverseGeocoderRequest = [ASIHTTPRequest requestWithURL:url];
    self.reverseGeocoderRequest.delegate = self;
    [self.reverseGeocoderRequest startAsynchronous];
}

顺便说一句,Google的API有规则,就像Apple的规则一样。请务必阅读文档,特别是关于配额。

By the way, Google's API has rules, just like Apple's does. Make sure you read the docs, especially regarding quotas.

这篇关于MKErrorDomain错误4 iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆