0

如何删除由 CLLocationManager 发送的缓存数据以及如何提高其准确性。每次我启动应用程序时,它都会给我缓存数据并在一段时间后更新它。我已经看到了几个线程,但我无法获得具体的 sol .谁能提供我的代码?我正在使用以下方法获取位置数据....

- (void)locationManager:(CLLocationManager *)manager
     didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation

我在这里设置了代表和准确性......

- (void)viewDidLoad {
[super viewDidLoad];
bestEffortAtLocation = nil;
latLocationArray = [[NSMutableArray alloc]init]; 
longLocationArray = [[NSMutableArray alloc]init];
locationManager =[[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.distanceFilter =  kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];

}

我也可以使用 CLLocationManager 来计算人行进的距离吗?

4

2 回答 2

1

There doesn't seem to be a way to dump the cached data. The docs recommend using the timestamp property of the CLLocation object to determine how recent the data is, which is what I do.

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
    //wait until we get a recent location, no more than 2 minutes old
    if([newLocation.timestamp timeIntervalSinceNow] <= (60 * 2)){
        DLog(@"New location:\n\tLat: %f\n\tLon: %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude)
        //turn off location updates
        [self.locManager stopUpdatingLocation];
        DLog(@"Stopping Location Updates");
        //Do stuff
    }
}

In my testing I haven't had to wait more than a second or two before I get new data.

On your second point, you could have a variable that you add to whenever you get a location update. The distance between updates can be pretty easy to get using CLLocation's distanceFromLocation: method.

于 2010-06-22T12:59:46.447 回答
0

而不是将 distanceFilter 设置为 kCLDistanceFilterNone

即 locationManager.distanceFilter = kCLDistanceFilterNone;

您可以给 distanceFilter 一些值并检查

例如 locationManager.distanceFilter =0.5f;

要计算距离旅行,您必须实施 didUpdateToLocation: fromLocation:

你必须在哪里找到新的纬度和经度

最后 CLLocationObject = newLocation;

CLLocationDistance yourdistance = [newLocation getDistanceFrom:CLLocationObject];

NSString *distance = [[NSString alloc] initWithFormat:@"%gm", yourdistance ];

NSLog(@"你有旅行=%@",距离);

于 2010-06-22T16:06:17.933 回答