0

When applications state changed to "applicationEnterBackground", -mapView didUpdateUserLocation method doesn't refresh so receiving device's location is being impossible. So I can't draw user's traveled roads to the map. It only draws just one line starting from the point user started walking to the end point that user stopped walking.

Is there any method that I can draw users traveled roads in applicationEnterBackground state.

- (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];
}
  • 2
    You will need to add the required background mode for location updates. There is a tutorial here: http://www.raywenderlich.com/29948/backgrounding-for-ios – Gary Riches Jan 27 '15 at 13:56
  • I've already added Required Background Modes to info.plist. My problem is this: app doesn't drawing the road when background is in background mode. – Tamer Şengöz Jan 27 '15 at 14:14
  • You will get a call back from the CCLocationManager when your location changes. You could draw the line then. Look up locationManager:didUpdateLocations: – Gary Riches Jan 27 '15 at 14:26

0 Answers0