iOS10在iPhone 6 Plus上。一个小型应用程序应用程序抓取GPS坐标并将其发送到远程Web服务。在iPhone地图上,用户位置正确显示,但是检索的坐标:
location.coordinate.latitude,
location.coordinate.longitude
距地图说我是我的位置0.5英里!无论我搬到哪里,这都是一致的。
我遵循苹果的最佳实践,并使用委托方法如下:这些坐标是不正确的。
// Delegate method from the CLLocationManagerDelegate protocol.
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
CLLocation* location = [locations lastObject];
NSDate* eventDate = location.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (abs(howRecent) < 15.0) {
// Log the data
NSLog(@"latitude %+.6f, longitude %+.6fn",
location.coordinate.latitude,
location.coordinate.longitude);
}
}
我将位置精度设置为如下:
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
i对GPS坐标进行了30秒的样品,以确保我获得最佳准确性。
我已经在2个不同的iPhone上尝试了此问题,都显示了同一问题。预先感谢。
我终于找到了导致问题的原因。我目前在中国...这就是神秘偏移的原因。中国的地图是"偏移"。如果您有兴趣,这里有一篇关于它的帖子,可以使我免于撕开头发。http://www.sinosplice.com/life/archives/2013/07/16/a-more-complete-ios-solution-solution-solution-to-to-the-china-china-gps-offset-problem。
中国使用称为GCJ-02的映射投影,该投影与西方的映射标准不同(WGS-84)。因此,如果您正在开发映射系统,则可能需要考虑到中国的旅行者!
无论如何都感谢您提供的编码建议。
您可以在方法中添加检查以再次更新位置,直到您达到所需的准确性:
// Delegate method from the CLLocationManagerDelegate protocol.
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
// You can check for either locationManager.desiredAccuracy or a value you'd like in meters
CLLocation* location = [locations lastObject];
if (location.horizontalAccuracy > locationManager.desiredAccuracy) {
//Do nothing yet
return;
}
NSDate* eventDate = location.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (abs(howRecent) < 15.0) {
// Log the data
NSLog(@"latitude %+.6f, longitude %+.6fn",
location.coordinate.latitude,
location.coordinate.longitude);
}
}