Storing a persistent CLLocation

Storing a persistent CLLocation

I think I am missing something obvious somewhere. I have a (CLLocation *)lastqueriedlocation defined in the header as a property and synthesized. I want to updated it in 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];     }	 }   

lastQueriedLocation is alloced and init'd in viewDidLoad.

The issue is that of course lastQueriedLocation = newLocation; results in an EXC_BAD_ACCESS. So what is the correct approach to persisting the lastQueriedLocation ?

If it helps make the problem more concrete - reSearch is calling a web service fetching POI within 2km of the location - so I only want to do it when we have moved 1km ... but I still want to keep the accuracy at best so I can highlight the nearest, scroll the map etc.

iPhone SDK: UIWebView


Focus OnLoad=“document.form_id.form_field_id.focus();” on the iPhone
You're just setting the iVar rather than the synthesised property, which means newLocation doesn't receive retained by the property. Getting access to touchesBegan/Moved/Ended to a UITableViewCell. Function Variable passed to setTimeout not working? Replace lastQueriedLocation = newLocation; with:. How to define a function that returns an NSString in Objective-C / Iphone SDK
[self setLastQueriedLocation:newLocation]; 
Or, if you'd rather use dot-notation:. Cocoa or Objective-C?
self.lastQueriedLocation = newLocation; 
Persisting Custom Objects

88 out of 100 based on 58 user ratings 958 reviews