首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在后台运行MKReverseGeocoder时出现问题

在后台运行MKReverseGeocoder时出现问题
EN

Stack Overflow用户
提问于 2011-09-14 21:43:54
回答 1查看 156关注 0票数 0

我正在使用MKReverseGeocoder (反向地理编码器)来检索用户的当前位置。我在CLLocation管理器的locationDidUpdatedToLocation方法中调用了反向地理编码器。

代码语言:javascript
复制
- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{

if(!reverseGeocoder )
    {
        NSLog(@"geocoder is nill");
        reverseGeocoder=[[MKReverseGeocoder alloc] initWithCoordinate:[newLocation coordinate]];
        reverseGeocoder.delegate=self;
        [reverseGeocoder start];
        NSLog(@"geocoder allocated");
    }

    else
    {
        NSLog(@"geocoder is not nill");


        if(reverseGeocoder.querying)
        {
        //do nothing ;
        }
        else
        [reverseGeocoder release];

    }

}

.querying属性用于确保仅当已完成查询时,才应释放反向地理编码器。但当应用程序在运行后3-4秒内崩溃并显示错误消息时

代码语言:javascript
复制
-[MKReverseGeocoder isQuerying]: message sent to deallocated instance

这里我漏掉了什么?

提前感谢您的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-09-14 22:23:51

会不会是因为您在发布地理编码器之前没有将它的委托设置为nil?还是因为你还没把指针钉上?

试试这个:

代码语言:javascript
复制
    if(reverseGeocoder.querying)
    {
            //do nothing ;
    }
    else
    {
            [reverseGeocoder setDelegate:nil];
            [reverseGeocoder release];
            reverseGeocoder = nil;
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7417330

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档