I’ve noticed that in my app, when I call startUpdatingLocation, my UI locks up briefly while i presume the device gathers the location data. Is this typical and is there any way to limit this? heres what my code looks like
-(void)getUserLocation {
if (!locationManager)
{
locationManager = [[CLLocationManager alloc]init];
}
[locationManager setDelegate:self];
[locationManager startUpdatingLocation];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
self.userCoordinate = newLocation.coordinate;
NSLog(@"user coordinate in location manager: %f,%f",self.userCoordinate.latitude,self.userCoordinate.longitude);
[locationManager stopUpdatingLocation];
locationManager = nil;
userLocationAvailable = YES;
[self getDataForScrollView];
}
any ideas? Thanks!
That’s because you are getting the location in the main thread, whereas the main thread is used to responsible for UI stuff . i.e. user touch events. that’s why u feel your app has a bit of lag.
That’s quite normal if you do a large task ( e.g. get data from web server) in main thread. You could put a “Loading” spin view to indicate the user instead of make your UI frozen.
Alternatively, you could try to get the location in another thread . I was trying to do this too but i have not succeeded yet. So i am currently doing with the first approach.