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

3 回答 3

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;

    }   
}
于 2012-08-30T13:51:16.943 回答
1

@Osama Khalifa,这取决于您如何使用location manager.

对于speed计算,我希望您使用satellite GPS (stopUpdatingLocation) 而不是 GPSthrough,mobile network (startMonitoringSignificantLocationChanges)因为GPSthrough 移动塔没有accuracyin speed

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

Note : more accurate results you ask consume more of iPhone battery power.
于 2012-08-30T13:49:53.273 回答
0

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

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

看看这个线程!

于 2012-08-30T13:53:41.290 回答