Reputation: 6829
I am trying to create simple GPS application just to display simple data in simulator. I have no errors just cant obtain data. "didFailWithError" method is the only I can get to work :), this is the code:
- (void)viewDidLoad
{
[super viewDidLoad];
lm = [[CLLocationManager alloc] init];
if([CLLocationManager locationServicesEnabled])
{
lm.delegate = self;
lm.desiredAccuracy = kCLLocationAccuracyBest;
//lm.distanceFilter = 1000.0f;
[lm startUpdatingLocation];
}
}
- (void) locationManager: (CLLocationManager *) manager
didUpdateToLocation: (CLLocation *) newLocation
fromLocation: (CLLocation *) oldLocation{
NSString *lat = [[ NSString alloc] initWithFormat:@"%g", newLocation.coordinate.latitude];
txtLatitude.text = lat;
NSString *lng = [[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.longitude];
txtLongitude.text = lng;
NSString *acc = [[NSString alloc] initWithFormat:@"%g", newLocation.horizontalAccuracy];
txtAccuracy.text = acc;
[acc release];
[lat release];
[lng release];
}
- (void) locationManager:(CLLocationManager *)manager
didFailWithError: (NSError *) error
{
NSString *msg = [[NSString alloc] initWithString:@"Error obtaining location"];
UIAlertView *alert = [[ UIAlertView alloc] initWithTitle:@"Error"
message:msg
delegate:nil
cancelButtonTitle:@"Done"
otherButtonTitles:nil];
[alert show];
[msg release];
[alert release];
}
Upvotes: 0
Views: 452
Reputation: 17372
It doesnt move ever in the simulator.
"Core Location Functionality
The relocation reported by the CoreLocation framework in the simulator is fixed at the following coordinates (accuracy 100 meters), which correspond to 1 Infinite Loop, Cupertino, CA 95014.
Latitude: 37.3317 North Longitude: 122.0307 West"
You could try adding a simple random or timed event which pings the didUpdate... method explicitly with fake data of your preference.
Upvotes: 2