核心位置检测到的最低速度

时间:2012-08-30 13:41:05

标签: ios core-location

我正在尝试开发一个显示用户速度和其他数据的应用程序。

我想知道Core Location可以检测到的最低速度是多少。当我在街上移动时,它的读数是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)];
}

3 个答案:

答案 0 :(得分: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 :(得分:1)

@Osama Khalifa,这取决于您使用location manager的方式。

对于speed计算,我希望您使用satellite GPS (stopUpdatingLocation)而不是GPSmobile network (startMonitoringSignificantLocationChanges),因为GPS通过移动塔不会{39}在accuracy中有speed

此外,您需要将desiredAccuracydistanceFilter值设置为最接近的值,以获得更多accurate值。

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

答案 2 :(得分:0)

我相信没有限制。你必须自己计算速度: distanceChange * timeSpan

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

看一下this帖子!