简体   繁体   中英

CLLocation not updating in iOS7

I implement the following code in viewDidLoad

locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone; 
locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
[locationManager startUpdatingLocation];

and i try to get my location every second via

 CLLocation *location = [locationManager location];
 CLLocationCoordinate2D coordinate = [location coordinate];
 NSLog(@"[%f,%f]",coordinate.latitude,coordinate.longitude);

i try to set the custom location in the iOS simulator, but the location never get updated, i had also tried it on my iphone device and it seems it only capture the first location and subsequent location is not been updated.

Please advise me on how to resolve it

Try this method to get continuous updated latitude and longitude

(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{  
    CLLocation *location_updated = [locations lastObject];   
    NSLog(@"updated coordinate are %@",location_updated);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM