2009-08-17 22 views
0

我想我在某处丢失了一些明显的东西。 我有一个(CLLocation *)lastqueriedlocation在标题中定义为一个属性和综合。我想在的LocationManager更新它:didUPdateToLocation:fromLocation:保存一个持久的CLLocation

 
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{ 

    CLLocationDistance dist = [lastQueriedLocation getDistanceFrom:newLocation]; 
    if (dist>1000) { 
     lastQueriedLocation = newLocation; 
     [self reSearch:lastQueriedLocation]; 
    } 

    if ([resultArray count] > 0) { 
     [self findAndDisplayNearestLocation:location]; 
    } 
} 

lastQueriedLocation被alloced和viewDidLoad中init'd。

问题是当然lastQueriedLocation = newLocation;结果在EXC_BAD_ACCESS。那么坚持lastQueriedLocation的正确方法是什么?

如果它有助于使问题更具体 - reSearch正在调用一个Web服务在位置2公里内获取POI - 所以我只想在移动1km时执行此操作...但我仍然希望保持准确性最好,所以我可以突出最近的,滚动地图等。

回答

1

你只是设置iVar而不是合成属性,这意味着newLocation不会被属性保留。

替换lastQueriedLocation = newLocation;有:

[self setLastQueriedLocation:newLocation]; 

或者,如果你想用点号:

self.lastQueriedLocation = newLocation;