James Stoddern
James Stoddern

Reputation: 417

Accuracy of iPhone Core Location Lat and Long

I have written a very basic iPhone app which records my Lat and Long everytime I get a CLLocation update. It stores these new positions in a GPX file, which I can then load up into a google map as a route overlay. When zoomed out the route looks fairly accurate, but when zoomed in, my route appears often to the side of the road I was actually driving on. One typical example of this might be that the location update happens as I approach a junction, and then again after I have turned the corner. When the two points are connected it appears that I have driven off road. Does anyone know if there is a way of improving this accuracy, or snapping my routes to the actual roads themselves?

My code for the update is as follows:

- (void)locationUpdate:(CLLocation *)location 
{   
////////////////////////////////////////////////////////
//Write to File
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *testFile = [documentsDirectory stringByAppendingPathComponent:@"routeplots.gpx"];

    BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:testFile];

    if(fileExists) {
        // get a handle to the file

        NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:testFile];

        // move to the end of the file
        [fileHandle seekToEndOfFile];

        NSString *data =[NSString stringWithFormat:@"\n<trkpt lat='%f' lon='%f'><name>%f</name></trkpt>", location.coordinate.latitude , location.coordinate.longitude , [location speed]];

        // move to the end of the file
        [fileHandle seekToEndOfFile];

        // convert the string to an NSData object
        NSData *textData = [data dataUsingEncoding:NSUTF8StringEncoding];

        // write the data to the end of the file
        [fileHandle writeData:textData];

        // clean up
        [fileHandle closeFile];
}
}

Thanks for looking at my issue, James

Upvotes: 0

Views: 776

Answers (2)

Janak Nirmal
Janak Nirmal

Reputation: 22726

Just have a look at this sample application provided by APPLE itself for what you are doing. Just download sample install in device and get idea how they are doing.

It Demonstrates how to draw a path using the Map Kit overlay, MKOverlayView, that follows and tracks the user's current location. The included CrumbPath and CrumbPathView overlay and overlay view classes can be used for any path of points that are expected to change over time. It also demonstrates what is needed to track the user's location as a background process.

Hope it helps.

Upvotes: 1

Prabha
Prabha

Reputation: 434

set the desiredAccuracy to AccuracyBest . locationManager.desiredAccuracy = KCLLocationAccuracyBest.

Upvotes: 1

Related Questions