2010-12-06 101 views
10

我開始使用coreLocation和mapkit框架的新應用程序。CLLocation返回負速度

我的問題是試圖讓當前的速度總是返回一個負值,我已經把我的iPhone與我的地方與一個良好的3G信號,並沒有關係,location.speed值總是-1。

這裏是重要的代碼:

#define kRequiredAccuracy 1500.0 //meters 
#define kMaxAge 60.0 //seconds 
在init方法

self.locationManager=[[CLLocationManager alloc] init]; 
self.locationManager.delegate=self; 
self.locationManager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters; 

然後didUpdateToLocation:

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

    NSTimeInterval ageInSeconds = [newLocation.timestamp timeIntervalSinceNow]; 
    NSLog(@"Location: %@", [newLocation description]); 

    if(newLocation.horizontalAccuracy > kRequiredAccuracy || fabs(ageInSeconds) > kMaxAge) 
    { 
     NSLog(@"inacurate position"); 
     [self.delegate inacuratePosition]; 

    } 
    else { 

    [self.delegate locationUpdate:newLocation andOldLocation:oldLocation]; 
    location=newLocation.coordinate; 


    } 


    if(tracking) 
    { 
    [self updatePosition]; 
    } 
    if(firstTime) 
    { 
     [self placeStartMark]; 
     firstTime=FALSE; 
    } 



} 

並最終在其中I」視圖控制器實施協議:

- (void)locationUpdate:(CLLocation *)newLocation andOldLocation:(CLLocation*)oldLocation{ 

    double speed = [newLocation speed] *3.6; 



    double altitude= [newLocation altitude]; 
    [self checkMaxSpeedAndAltitude:speed :altitude]; 
    if(speed< 0) 
     speed=0; 



    locationLabel.text=[NSString stringWithFormat:@"speed: %f km/h altitude: %f m", speed,altitude]; 
} 

我越來越瘋狂,所以如果有人知道任何解決方案,它肯定會有幫助。 謝謝

+0

您提到一個很好的3G信號時,這幾乎與'良好'的基於位置的應用程序無關。如果你對衛星沒有看法,你就不會得到好的信息。檢查您的水平精度小(小於200米),這是一個很好的作弊,看看你有衛星,而不只是細胞塔三角測量) – KevinDTimm 2010-12-06 16:55:57

+0

好的,謝謝,我會檢查它 – JonLOo 2010-12-06 17:10:44

回答

13

通常,如果使用的位置檢測機制不支持它,則會得到負高度和速度。例如,當使用Wi-Fi或小區三角測量時。你確定,你正在獲得GPS更新,那麼你在自由空間下進行測試?即使如此,您仍然會收到WiFi和手機信號塔位置更新,因此您必須將其過濾掉。

65米的水平精度是Wi-Fi位置更新的典型代表。