0

我编写了一个非常基本的 iPhone 应用程序,每次我收到 CLLocation 更新时都会记录我的纬度和经度。它将这些新位置存储在 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];
}
}

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

4

2 回答 2

1

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

于 2012-05-03T12:54:02.130 回答
1

看看APPLE 自己提供的这个示例应用程序就知道你在做什么。只需在设备中下载示例安装并了解他们的工作方式。

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.

希望能帮助到你。

于 2012-05-03T13:07:10.690 回答