作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试调用一个函数,以防自上次检查后移动的距离 > 30 m。根据 CLLocationDistance 的类描述,返回值以 m 为单位。
我使用这段代码:
[locationManager startUpdatingLocation];
if (!startingLocation)
startingLocation = locationManager.location;
// NSLog(@"Latitude:%f Longitude:%f", startingLocation.coordinate.latitude, startingLocation.coordinate.longitude);
updatedLocation = locationManager.location;
CLLocationDistance distance = [updatedLocation distanceFromLocation:startingLocation];
if (distance > 30) {
NSLog(@"%f",distance);
NSLog(@"Latitude:%f Longitude:%f", updatedLocation.coordinate.latitude, updatedLocation.coordinate.longitude);
[self stop];
带有 NSLog 的控制台输出返回 7946754.993111,我什至没有碰手机。任何建议表示赞赏!
最佳答案
两点之间有 8000 公里?我敢打赌第一个点是 0, 0,你离那里大约 8000 公里,对吧?
在任何情况下,请务必在使用位置坐标之前通过检查确保 horizontalAccuracy >=0 来仅使用有效位置。无效位置的 horizontalAccuracy 为负。
此外,您可能应该通过检查位置数据的使用年限来丢弃任何缓存的位置,如果它超过几秒就不要使用它。
参见 sample code here进行这些检查。
另一件需要注意的事情是,由于准确性的变化,您可能会得到显示错误运动的位置。参见 this answer了解详情。
关于ios - distanceFromLocation 在不移动最小位的情况下返回巨大的值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8391806/
我是一名优秀的程序员,十分优秀!