这是我的位置管理器代码
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters;
locationManager.distanceFilter = 200;
mapView.showsUserLocation=true;
[locationManager startUpdatingLocation];
这是另一个也用于 startupdatelocation 的函数
- (void)startLocationManager:(NSTimer *)timer
{
[locationManager startUpdatingLocation];
[timer invalidate];
timer = nil;
}
这是
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"Testing");
CLLocationCoordinate2D location;
location.latitude=newLocation.coordinate.latitude;
location.longitude=newLocation.coordinate.longitude;
[locationManager stopUpdatingLocation];
[NSTimer scheduledTimerWithTimeInterval:60
target:self
selector:@selector(startLocationManager:)
userInfo:nil
repeats:NO];
}
这工作正常,但应用程序不在后台运行。如果我删除NStimer
并且不停止位置管理器,则应用程序在后台运行得非常好。我希望位置管理器每 1 分钟运行一次以更新坐标。该应用程序还应该在后台运行。