我在散步期间记录了gps点数。下面显示每5秒钟保存一次坐标的功能。 我做了几个测试,但我不能得到我想要的正确的准确性。 (当测试天空时,谷歌地图上的测试也显示GPS信号良好)。iPhone Gps日志记录不准确
这里是代码:
-(void)viewDidAppear:(BOOL)animated{
if (self.locationManager == nil){
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
locationManager.delegate = self;
// only notify under 100 m accuracy
locationManager.distanceFilter = 100.0f;
locationManager.desiredAccuracy= kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
}
- start logging
[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(getData) userInfo:nil repeats:YES];
</code>
<code>
-(void)getData{
int distance;
// re-use location.
if ([ [NSString stringWithFormat:@"%1.2f",previousLat] isEqualToString:@"0.00"]){
// if previous location is not available, do nothing
distance = 0;
}else{
CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:previousLat longitude:previousLong];
CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:latGlobal longitude:longGlobal];
distance = [loc1 getDistanceFrom: loc2];
}
// overwrite latGlobal with new variable
previousLat = latGlobal;
previousLong = longGlobal;
// store location and save data to database
// this part goes ok
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
// track the time to get a new gps result (for gps indicator orb)
lastPointTimestamp = [newLocation.timestamp copy];
// test that the horizontal accuracy does not indicate an invalid measurement
if (newLocation.horizontalAccuracy < 0) return;
// test the age of the location measurement to determine if the measurement is cached
// don't rely on cached measurements
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
if (locationAge > 5.0) return;
latGlobal = fabs(newLocation.coordinate.latitude);
longGlobal= fabs(newLocation.coordinate.longitude);
}
我已经采取了积结果的截图(步行需30分钟),什么我'尝试acomplish一个例子: http://www.flickr.com/photos/[email protected]/4623969014/
我真的希望有人能让我走向正确的方向。
嗨Andiih,谢谢你的建议。也许反其道而行更好。根据准确度存储最佳的“didUpdateLocation”结果,并且每5秒最多保存1个点。过滤,例如基于速度的最大距离,确实会产生更清晰的结果,但是对我而言,这是一步。当我测试时,我会发布我的发现和新代码。谢谢 – Martijn 2010-05-20 11:34:07
今天我花了一些时间看这个。我注意到,糟糕的“jumppoint”(对你而言)始终是同一点。我想知道你是否可以过高的相对速度和重复访问同一点。 – Andiih 2010-05-20 19:20:27
这将变成讨论。如果你想通过这个联系我,请发邮件给我,并告诉我,我正在取得一些进展,但是在我们开展工作时共享数据集等是件好事:SO是针对问题和答案而不是讨论。 – Andiih 2010-05-21 12:28:13