I try to get the last current location of the user by method didUpdateToLocation:newLocation:fromLocation:oldLocation:and save it in my ivarCLLocation *userCurrentLocation
I get this error when I try to read userCurrentLocation
-[NSCFNumber coordinate]: unrecognized selector sent to instance 0x586b220
- (void) locationManager:(CLLocationManager *) manager
didUpdateToLocation:(CLLocation *) newLocation
fromLocation:(CLLocation *) oldLocation {
fromLocation:(CLLocation *) oldLocation {
if (oldLocation == nil) {
SVGeocoder *geocodeRequest = [[SVGeocoder alloc]
initWithCoordinate:CLLocationCoordinate2DMake(newLocation.coordinate.latitude, newLocation.coordinate.longitude)];
[geocodeRequest setDelegate:self];
[geocodeRequest startAsynchronous];
[geocodeRequest release];
isCurrentLocation = YES;
}
userCurrentLocation = newLocation;
NSLog(@"didUpdateToLocation - Lat:%f Long:%f", userCurrentLocation.coordinate.latitude, userCurrentLocation.coordinate.longitude);
}
Toolbar button to display the user's current location
-(IBAction) showLocation:(id) sender {
NSLog(@"Lat:%f Long:%f", userCurrentLocation.coordinate.latitude, userCurrentLocation.coordinate.longitude);
NSLog(@"Show Location Called");
SVGeocoder *geocodeRequest = [[SVGeocoder alloc]
initWithCoordinate:CLLocationCoordinate2DMake(userCurrentLocation.coordinate.latitude, userCurrentLocation.coordinate.longitude)];
[geocodeRequest setDelegate:self];
[geocodeRequest startAsynchronous];
[geocodeRequest release];
}
I set the property and synthesized userCurrentLocation as such:
MapViewController.h
@interface MapViewController : UIViewController <CLLocationManagerDelegate, MKMapViewDelegate> {
CLLocation *userCurrentLocation;
}
@property (nonatomic, retain) CLLocation *userCurrentLocation;
@end
MapViewController.m
@synthesize userCurrentLocation;
- (void)viewDidLoad {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
userCurrentLocation = [[CLLocation alloc] init];
}
source
share