当应用程序状态更改为“applicationEnterBackground”时,-mapView didUpdateUserLocation方法不会刷新,因此无法接收设备的位置。所以我无法将用户的旅行道路绘制到地图上。它只从用户开始行走的点开始到用户停止行走的终点只绘制一条线。
我是否可以使用任何方法绘制用户在applicationEnterBackground状态下行走的道路。
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
NSLog(@"%@ ----- %@", self, NSStringFromSelector(_cmd));
CLLocation *location = [[CLLocation alloc] initWithLatitude:userLocation.coordinate.latitude
longitude:userLocation.coordinate.longitude];
NSLog(@"latitude %+.6f, longitude %+.6f\n", userLocation.coordinate.latitude, userLocation.coordinate.longitude);
[_latitudeArray addObject:[NSString stringWithFormat:@"%f",userLocation.coordinate.latitude]];
[_longitudeArray addObject:[NSString stringWithFormat:@"%f",userLocation.coordinate.longitude]];
// check the zero point
if (userLocation.coordinate.latitude == 0.00f ||
userLocation.coordinate.longitude == 0.00f)
return;
// check the move distance
if (_points.count > 0) {
CLLocationDistance distance = [location distanceFromLocation:_currentLocation];
if (distance < 5)
return;
}
if (nil == _points) {
_points = [[NSMutableArray alloc] init];
}
[_points addObject:location];
_currentLocation = location;
[self configureRoutes];
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(userLocation.coordinate.latitude, userLocation.coordinate.longitude);
[self.mapView setCenterCoordinate:coordinate animated:YES];
}