Reputation: 2566
I am currently working on a location based ios application. I am using didupdatelocation
delegate method for showing user's current location. It works fine when I connect my device to internet. But when I disconnect the internet, it behaves strange and didupdatelocation
is not getting called further. Please give a solution.
EDITED with code details
- (void)viewDidLoad
{
[super viewDidLoad];
locationManager = [[CLLocationManager alloc]init]; // initializing locationManager
locationManager.delegate = self; // we set the delegate of locationManager to self.
locationManager.desiredAccuracy = kCLLocationAccuracyBest; // setting the accuracy
[locationManager startUpdatingLocation]; //requesting location updates
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
UIAlertView *errorAlert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"There was an error retrieving your location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[errorAlert show];
NSLog(@"Error: %@",error.description);
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *crnLoc = [locations lastObject];
latitude.text = [NSString stringWithFormat:@"%.8f",crnLoc.coordinate.latitude];
longitude.text = [NSString stringWithFormat:@"%.8f",crnLoc.coordinate.longitude];
altitude.text = [NSString stringWithFormat:@"%.0f m",crnLoc.altitude];
speed.text = [NSString stringWithFormat:@"%.1f m/s", crnLoc.speed];
}
Upvotes: 1
Views: 670
Reputation: 3513
@ANSHAD per your comment, if you are using an older iPad without GPS, the only way you can get location data is with WiFi so if you turn off WiFi, you will not get location updates. If you want GPS without WiFi you can buy an external GPS module see here
Upvotes: 1
Reputation: 1303
You can use the base GPS of the iPhone which works without the internet too. To access it you need to use the CoreLocation framework.
You can refer to this : CoreLocation methods to use the GPS data.
Let me know if any other help required.
Upvotes: 0