我想我遗漏了一些明显的东西。 我在头中定义了一个(cllocation*)lastqueriedlocation作为属性并进行了合成。我想在locationManager:didUpdateToLocation:FromLocation中更新它:
- (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]; } }
最后一个queriedLocation已分配并在viewdidload中初始化。
当然,问题是 lastQueriedLocation = newLocation; 结果在 EXC_BAD_ACCESS . 那么,保持上一个查询位置的正确方法是什么?
lastQueriedLocation = newLocation;
EXC_BAD_ACCESS
如果这有助于使问题更加具体化——研究人员称一个Web服务在距离地点2公里的范围内获取POI——那么我只想在我们移动了1公里的时候做这件事……但我仍然希望保持最好的准确性,这样我可以突出显示最近的,滚动地图等。
您只是设置了ivar而不是合成属性,这意味着newlocation不会被属性保留。
替换 lastQueriedLocation = newLocation; 使用:
[self setLastQueriedLocation:newLocation];
或者,如果您愿意使用点符号:
self.lastQueriedLocation = newLocation;