Change CLLocation Coordinates

I am new to Objective-C, so this may be a trivial problem:

After initializing the location:

CLLocation *currentPoint = [[CLLocation alloc] initWithLatitude:0 longitude:0]: 

How can I change the latitude and longitude later?

+4
source share
2 answers

CLLocation objects are immutable (you cannot change them). According to the docs:

Typically, you use the CLLocationManager object to instantiate this class based on the last known location of the user device. However, you can create instances yourself if you want to cache user location data or get the distance between two different coordinates.

+1
source

Here is an example of how to change CLLocation:

 - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{ newLocation = [[[CLLocation alloc] initWithCoordinate:CLLocationCoordinate2DMake(newLocation.coordinate.latitude, -1.1874988592864875) altitude:newLocation.altitude horizontalAccuracy:newLocation.horizontalAccuracy verticalAccuracy:newLocation.verticalAccuracy timestamp:newLocation.timestamp] autorelease]; 

And here is another example of creating a new CLLotation:

 CLLocation *newLocation = [[[CLLocation alloc] initWithCoordinate:CLLocationCoordinate2DMake(41.44994138650804, -1.1874988592864875) altitude:0 horizontalAccuracy:0 verticalAccuracy:0 timestamp:[NSDate date]] autorelease]; 
+11
source

All Articles