1

I'm trying to develop an application which displays user speed and some other data.

I want to know what is the minimum speed that Core Location can detect. When I'm moving in the street it's reading is 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)];
}
Osama Khalifa
  • 363
  • 5
  • 10

3 Answers3

4

You should set up distanceFilter and desiredAccuracy properties.

This is Jano's code

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];
}

Speed calculating:

-(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;

    }   
}
Community
  • 1
  • 1
tikhop
  • 2,012
  • 14
  • 32
1

@Osama Khalifa, it depends on how you are using location manager.

For speed calculation i would prefer you to use satellite GPS (stopUpdatingLocation) instead of GPS through mobile network (startMonitoringSignificantLocationChanges) because GPS through mobile tower doesn't have accuracy in speed.

Also you need to set desiredAccuracy and distanceFilter value to nearest one to get more accurate value.

Note : more accurate results you ask consume more of iPhone battery power.
saadnib
  • 11,145
  • 2
  • 33
  • 54
0

I believe there is no limitation. You have to calculate the speed yourself with: distanceChange * timeSpan

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

Have a look at this thread!

Community
  • 1
  • 1
E. Lüders
  • 1,495
  • 1
  • 12
  • 27