Can anyone let me know why the below code works on the simulator but not my iPhone? The idea is to specify a longitude and latitude (like home location), then when you press update (a button) it calculates how far you are from home (or whatever location you have inputted).
The error is the following--
"[CLLocation distanceFromLocation:]: unrecognized selector"...uncaught exception.
Any help is appreciated.
Adam
Code:
- (void)viewDidLoad {
locationManager=[[CLLocationManager alloc]init];
[locationManager setDelegate:self];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager startUpdatingLocation];
}
-(IBAction)update:(id)sender
{
[self.view setNeedsDisplay];
}
#pragma mark -
#pragma mark CLLocationManagerDelegateMethods
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
if (startingPoint==nil) {
self.startingPoint=newLocation;
}
CLLocation*myHome=[[CLLocation alloc]initWithLatitude:41.513546 longitude:-81.557974];
CLLocationDistance theDistance=[startingPoint distanceFromLocation:myHome];
distanceLabel.text=[[NSString alloc]initWithFormat:@"%gm",theDistance];
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"could not find location: %@",error);
}
The error is the following--
"[CLLocation distanceFromLocation:]: unrecognized selector"...uncaught exception.
Any help is appreciated.
Adam