iPhone Core位置Lat和Long的准确性

时间:2012-05-03 12:32:01

标签: iphone google-maps core-location latitude-longitude

我写了一个非常基本的iPhone应用程序,每当我获得CLLocation更新时,它会记录我的Lat和Long。它将这些新位置存储在GPX文件中,然后我可以将其作为路径叠加层加载到谷歌地图中。当缩小时,路线看起来相当准确,但是当放大时,我的路线经常出现在我实际驾驶的路边。一个典型的例子可能是当我接近一个交叉点时发生位置更新,然后在我转弯后再次发生。当这两点连接起来时,似乎我已经离开了道路。有没有人知道是否有办法提高这种准确性,或者将我的路线贴到实际道路上?

我的更新代码如下:

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

感谢您查看我的问题,詹姆斯

2 个答案:

答案 0 :(得分:1)

将desiredAccuracy设置为AccuracyBest。 locationManager.desiredAccuracy = KCLLocationAccuracyBest。

答案 1 :(得分:1)

请看看APPLE本身提供的sample application您正在做的事情。只需在设备中下载示例安装,并了解它们的运行方式。

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.

希望它有所帮助。