1

When I first start location updating the value will not be 0 always. Sometimes it is but sometimes I get values slightly above 0. I will get a value such as 2. So of coarse I hit the stop and start again then ill get a smaller value and continue doing so until I get zero. Even though my desired distance filter is 250 meters ill get values at the start below this! Why is this happening and how do I deal with this.The following is especially a problem when starting this indoors(giving me the idea that this is some G-P-S initial establishing problem). I can deal with this with a simple alert view to confirm the user is outdoors before starting but this occurs sometimes when outside so I want this issue solved. Also when it does start at 0 and I start driving immediately I get inaccurate values. Seems like I have to wait like 30 seconds before the starting to drive before I get accurate readings.

MY GUESS FOR A SOLUTION: NEED TO CONFIRM SOME HOW I HAVE A SOLID G-P-S CONNECTION BEFORE THE LOCATION UPDATING BEGINS.

Don't see anything in the CLLocationManager class reference that can be of any help to the above solution.

CLLocationManager class reference

Heres an example of what I mean with the starting and stopping when it doesn't start at 0.

Trigger Start - > Location = 1.1 km
Trigger Stop
Trigger Start - > Location = .98 km
Trigger Stop
Trigger Start - > Location = .55 km
Trigger Stop
Trigger Start - > Location = .02 km
Trigger Stop
Trigger Start - > Location = 0 km (finally where it should start from)

Here is my code:

@interface DriveLog (){

    CLLocationDistance totalDistanceBetween;
    NSString *tripString;
    Settings *settingsVC;
    CGFloat km;

}
- (void)viewDidLoad{

    totalDistanceBetween = 0;

    locationManager = [[CLLocationManager alloc] init];
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationManager.delegate = self;
    locationManager.distanceFilter = 250;
    startLocation = nil;

    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (IBAction)start:(id)sender {

    [locationManager startUpdatingLocation];
}


- (IBAction)stop:(id)sender {

    totalDistanceBetween = 0;
    startLocation = nil;
    [locationManager stopUpdatingLocation];

}

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

    if (startLocation == nil){
        totalDistanceBetween = 0;
        self.startLocation = newLocation;
    }
    CLLocationDistance distanceBetween = [newLocation distanceFromLocation:startLocation ];
    self.startLocation = newLocation;
    totalDistanceBetween += distanceBetween;

    if(kmOrMile == 0){
        km = totalDistanceBetween * 0.001;

    }else{
        km = totalDistanceBetween * 0.000621371192237334;
    }

    tripString = [[NSString alloc]
                            initWithFormat:@"%.02f%@",
                            km, kmOrMileString];

    distance.text = tripString;
}
4GetFullOf
  • 1,738
  • 4
  • 22
  • 47

2 Answers2

0

You can use the horizontalAccuracy property on CLLocation to judge if the current location is good enough for your needs. Check its accuracy in the delegate callback, if it is not good enough don't calculate the distance with it.

The desiredAccuracy setting is exactly that, desired not promised. From the docs:

When requesting high-accuracy location data, the initial event delivered by the location service may not have the accuracy you requested.

Tark
  • 5,153
  • 3
  • 24
  • 23
  • How should I implement this? Thinking of doing something like this. if (startLocation.horizontalAccuracy < 0) return; If i monitor the values in my log though Im always getting values above 0. 200+ to be exact. And still getting mixed results. Sometimes it starts at and 0 and sometimes it doesn't. Like I can get a value that says 200 and starts at 0km and also get a value like 1100 and still start at 0 and vice versa. Not seeing any pattern I can pick up on? – 4GetFullOf Nov 20 '13 at 19:36
  • After more frequent use I get values from horizontal accuracy close to 0 like 30 that still give me inaccurate starting values. Closer to zero means more accurate correct? – 4GetFullOf Nov 20 '13 at 20:17
  • What do you mean inaccurate starting values? What is 200 and 1100 and 0? As long as you are discarding locations that are insufficiently accurate, your distance calculation should remain accurate within bounds. Something like: `if (newLocation.horizontalAccuracy > AccuracyThreshold) return;` – Tark Nov 20 '13 at 22:56
  • Those are values that are being returned by the horizontalAccuracy property. Whats the accuracy threshold? – 4GetFullOf Nov 21 '13 at 00:58
  • Whatever you want it to be. How accurate is accurate enough for you? – Tark Nov 21 '13 at 08:21
  • That really depends on your app specifications. How are you deciding at the moment that a location is not accurate enough? How much error is acceptable in your distance calculation? – Tark Nov 21 '13 at 18:34
  • Thats what i mentioned in my earlier comment Im monitoring the value being received from my horizontalAccuracy property and the accuracy of my distance travelled. I don't think this is going to fix my problem as a very low value received from my horizontalAccuracy property can give me accurate readings and a high number can give me inaccurate readings but the same is true vice versa. Also true with high numbers and vice versa. So theres no value to check for as 20, 100, 500, 1000, 1500, etc give me accurate values and 20, 100, 500, 1000, 1500, etc also give me inaccurate values. – 4GetFullOf Nov 21 '13 at 20:27
0

The problem was with my device. My device was in rough shape and has had underwater experiences I guess making the hardware inside a little defected. Just a reminder to everyone to always try on another device. Could always be your phone even when you least expect it.

4GetFullOf
  • 1,738
  • 4
  • 22
  • 47