4

I'm new to Objective C, so this might be a trivial issue:

After initializing a location:

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

how can I change the latitude and longitude later?

2 Answers 2

11

Here's an example of how to modify a 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's another example of how to create a new CLLotation:

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

CLLocation objects are immutable (you can't change them). According to the docs:

Typically, you use a CLLocationManager object to create instances of this class based on the last known location of the user’s device. You can create instances yourself, however, if you want to cache custom location data or get the distance between two different coordinate points.

1
  • Thanks, so I'm going to use variables to store the location and make it changeable.
    – Mike
    Jul 30, 2009 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.