高德 定位稀释

需求:司机接到乘客后要上传经纬度,总不能一秒一个的上传吧。需要把经纬度拉稀。

参考文献:
iOS开发:后台定位并上传数据到服务器

主要代码段

- (void)adjustDistanceFilter:(CLLocation *)location {
    
    if (location.speed < self.minSpeed) {
        if (fabs(self.locationManager.distanceFilter - self.minFilter) > 0.1f) {
            self.locationManager.distanceFilter = self.minFilter;
        }
    }
    else {
        CGFloat lastSpeed = self.locationManager.distanceFilter / self.minInteval;
        if (((fabs(lastSpeed - location.speed) / lastSpeed) > 0.1f ) || (lastSpeed < 0)) {
            CGFloat newSpeed  = (int)(location.speed+0.5f);
            CGFloat newFilter = newSpeed*self.minInteval;
            self.locationManager.distanceFilter = newFilter;
        }
    }
}

我的demo

你可能感兴趣的:(高德 定位稀释)