我正在开发步行轨道类型的应用程序,但面临的问题是当应用程序处于后台时位置将如何更新。我正在地图上绘制一条路径作为位置更新和一个计时器。然后请建议我如何处理它。这是我的代码
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
if(!newLocation) return;
if ((oldLocation.coordinate.latitude != newLocation.coordinate.latitude) &&
(oldLocation.coordinate.longitude != newLocation.coordinate.longitude))
{
// to draw path as new location find
jogPoint = [[JogPoint alloc] initWithCenterCoordinate:newLocation.coordinate];
[jogPoints addObject:jogPoint];
if([jogPoints count] >= 5) {
[self.mapView addOverlay:jogPoint];
CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:oldLocation.coordinate.latitude longitude:oldLocation.coordinate.longitude];
CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude];
// returns distance in meters
distnc+=[loc1 distanceFromLocation:loc2] ;
distanceLabel.text=[NSString stringWithFormat:@"%lf",distnc];
// jogInfo.distance += ([loc1 distanceFromLocation:loc2]) * 0.000621371192;
// jogInfo.eclapsedTime = (CFAbsoluteTimeGetCurrent() - startTime) * 1000 * 60;
}
}
}