11

Location Servicesいくつかのアプリで使用しています。locationManager:didUpdateToLocation:fromLocation:悪い場所、不正確な場所、または遠すぎる場所を除外するために、自分の方法で使用する方法があります。そして、gpsの「ジッター」を最小限に抑えるため。これが私が使用するものです:

/**
 * 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

誰かがこの方法をより正確にするために何か改善がありますか?66は高すぎて、horizontalAccuracy多くの無効な場所を受け取りますか?これを下げる必要がありますか?

iPhoneのGPSがもたらす「ジッター」を取り除く方法はありますか?

4

3 に答える 3

7

これらに加えて、私が使用するものがもう 1 つあります。

if(self.lastKnownLocation)
{
     CLLocationDistance dist = [newLocation distanceFromLocation:self.lastKnownLocation];

     if(dist > newLocation.horizontalAccuracy)
     {
          //.....
     }
}

self.lastKnownLocation実際に私が持っている最後の有効な場所はどこですか。それは次のとおりです。

@property(nonatomic, copy) CLLocation *lastKnownLocation;
于 2012-05-24T17:17:51.047 に答える
5
-(void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
 if (!newLocation)
    {
        NSLog(@"Filter out points by invalid accuracy");
        return;
    }

    // Filter out points by invalid accuracy
    if (newLocation.horizontalAccuracy < 0)
    {
        return;
    }
    if(oldLocation.coordinate.latitude>90 && oldLocation.coordinate.latitude<-90 && oldLocation.coordinate.longitude>180 && oldLocation.coordinate.longitude<-180)
    {   
       NSLog(@"old");
       return;
    }
    if(newLocation.coordinate.latitude>90 || newLocation.coordinate.latitude<-90 || newLocation.coordinate.longitude>180 || newLocation.coordinate.longitude<-180)
    {
       NSLog(@"new");
       return;
    }

    ///////   
    NSDate *eventDate=newLocation.timestamp;   
    NSTimeInterval eventinterval=[eventDate timeIntervalSinceNow];


    if (abs(eventinterval)<30.0)
    {           
       if (newLocation.horizontalAccuracy>=0 && newLocation.horizontalAccuracy<20)
       { 
          **//finally you are getting right updated value here....**
       }          
    }           
 }  
于 2012-12-20T12:54:04.547 に答える