2012-08-30 59 views
1

我試圖開發一個顯示用戶速度和一些其他數據的應用程序。核心位置檢測到的最低速度

我想知道核心位置可以檢測到的最小速度是多少。當我在街上移動時,它的讀數是0.00。

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{ 
    //i display some other data here 
    speedLbl.text =[NSString stringWithFormat:@"Speed: %f km/hr",([lastLocation speed]*3.6)]; 
} 

回答

4

您應該設置distanceFilterdesiredAccuracy屬性。

這是Jano的代碼

self.locationManager = [[[CLLocationManager alloc] init] autorelease]; 
self.locationManager.delegate = self; 

/* Pinpoint our location with the following accuracy: 
* 
*  kCLLocationAccuracyBestForNavigation highest + sensor data 
*  kCLLocationAccuracyBest    highest  
*  kCLLocationAccuracyNearestTenMeters 10 meters 
*  kCLLocationAccuracyHundredMeters  100 meters 
*  kCLLocationAccuracyKilometer   1000 meters 
*  kCLLocationAccuracyThreeKilometers 3000 meters 
*/ 
self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; 

/* Notify changes when device has moved x meters. 
* Default value is kCLDistanceFilterNone: all movements are reported. 
*/ 
self.locationManager.distanceFilter = 10.0f; 

/* Notify heading changes when heading is > 5. 
* Default value is kCLHeadingFilterNone: all movements are reported. 
*/ 
self.locationManager.headingFilter = 5; 

// update location 
if ([CLLocationManager locationServicesEnabled]){ 
    [self.locationManager startUpdatingLocation]; 
} 

速度計算:

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{ 
    double speed = newLocation.speed; 

    //another way 
    if(oldLocation != nil) 
    { 
     CLLocationDistance distanceChange = [newLocation getDistanceFrom:oldLocation]; 
     NSTimeInterval sinceLastUpdate = [newLocation.timestamp timeIntervalSinceDate:oldLocation.timestamp]; 
     speed = distanceChange/sinceLastUpdate; 

    } 
} 
1

@Osama Khalifa,這取決於你如何使用location manager

對於speed計算我寧願你使用satellite GPS (stopUpdatingLocation),而不是通過GPSmobile network(startMonitoringSignificantLocationChanges)因爲GPS通過移動塔沒有accuracyspeed

您還需要設置desiredAccuracydistanceFilter值到最近的一個以獲取更多accurate值。

Note : more accurate results you ask consume more of iPhone battery power. 
0

我相信沒有限制。你必須自己計算速度: distanceChange * timeSpan

distanceChange = [newLocation getDistanceFrom:oldLocation] timeSpan = time when retrieved new Location - time when retrieved old Location

看一看this線!