我在一些應用程序中使用Location Services
。我在我的locationManager:didUpdateToLocation:fromLocation:
方法中使用了一種方法來過濾不良,不準確或太遠的位置。並儘量減少GPS「抖動」。這裏是我使用的:iOS位置服務過濾無效/不準確位置的方法
/**
* Check if we have a valid location
*
* @version $Revision: 0.1
*/
+ (BOOL)isValidLocation:(CLLocation *)newLocation withOldLocation:(CLLocation *)oldLocation {
// Filter out nil locations
if (!newLocation) return NO;
// Filter out points by invalid accuracy
if (newLocation.horizontalAccuracy < 0) return NO;
if (newLocation.horizontalAccuracy > 66) return NO;
// Filter out points by invalid accuracy
#if !TARGET_IPHONE_SIMULATOR
if (newLocation.verticalAccuracy < 0) return NO;
#endif
// Filter out points that are out of order
NSTimeInterval secondsSinceLastPoint = [newLocation.timestamp timeIntervalSinceDate:oldLocation.timestamp];
if (secondsSinceLastPoint < 0) return NO;
// Make sure the update is new not cached
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
if (locationAge > 5.0) return NO;
// Check to see if old and new are the same
if ((oldLocation.coordinate.latitude == newLocation.coordinate.latitude) && (oldLocation.coordinate.longitude == newLocation.coordinate.longitude))
return NO;
return YES;
}//end
有沒有人有任何改善這種方法,使其更加準確?是過高的horizontalAccuracy
會收到很多無效的位置?我應該降低這個嗎?
有沒有辦法讓iPhone上的gps「抖動」
我開始對類似的工作。我正在考慮實施卡爾曼濾波器,但我不確定這是否會被殺死。我很想看到人們在這個問題上的答案。 – scord
是的,我也看了一個卡爾曼濾波器,但是這個數學很瘋狂。 –