我在散步期間記錄了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