Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios mapView didUpdateUserLocation不';t刷新_Ios_Mkmapview_Mkmapviewdelegate - Fatal编程技术网

Ios mapView didUpdateUserLocation不';t刷新

Ios mapView didUpdateUserLocation不';t刷新,ios,mkmapview,mkmapviewdelegate,Ios,Mkmapview,Mkmapviewdelegate,当应用程序状态更改为“applicationEnterBackground”时,-mapView didUpdateUserLocation方法不会刷新,因此无法确定接收设备的位置。因此,我无法将用户的行驶道路绘制到地图上。它仅从用户开始行走的点到用户停止行走的终点绘制一条线 是否有任何方法可以在ApplicationInterBackground状态下绘制用户行驶的道路 - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MK

当应用程序状态更改为“applicationEnterBackground”时,-mapView didUpdateUserLocation方法不会刷新,因此无法确定接收设备的位置。因此,我无法将用户的行驶道路绘制到地图上。它仅从用户开始行走的点到用户停止行走的终点绘制一条线

是否有任何方法可以在ApplicationInterBackground状态下绘制用户行驶的道路

- (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];
}
-(void)mapView:(MKMapView*)mapView didUpdateUserLocation:(MKUserLocation*)userLocation
{
NSLog(@“%@----------%@”,self,NSStringFromSelector(_cmd));
CLLocation*location=[[CLLocation alloc]initWithLatitude:userLocation.coordinate.latitude
经度:userLocation.coordinate.longitude];
NSLog(@“纬度%+.6f,经度%+.6f\n”,userLocation.coordinate.latitude,userLocation.coordinate.longitude);
[_latitudarrayaddobject:[NSString stringWithFormat:@“%f”,userLocation.coordinate.latitude];
[\u longitudaray addObject:[NSString stringWithFormat:@“%f”,userLocation.coordinate.longitude];
//检查零点
如果(userLocation.coordinate.latitude==0.00f||
userLocation.coordinate.longitude==0.00f)
回来
//检查移动距离
如果(_points.count>0){
CLLocationDistance距离=[location distanceFromLocation:_currentLocation];
如果(距离<5)
回来
}
如果(零==\u点){
_points=[[NSMutableArray alloc]init];
}
[_pointsaddobject:location];
_当前位置=位置;
[自配置路由];
CLLocationCoordinate2D坐标=CLLocationCoordinate2DMake(userLocation.coordinate.latitude,userLocation.coordinate.longitude);
[self.mapView setCenterCoordinate:坐标动画:是];
}

您需要添加位置更新所需的背景模式。这里有一个教程:我已经在info.plist中添加了所需的背景模式。我的问题是:当后台处于后台模式时,应用程序不会绘制道路。当您的位置发生变化时,您将收到CCLocationManager的回电。你可以划清界限。查找位置管理器:didUpdateLocations: