Location.distanceTo 在近似距离计算中使用 error 参数?

发布于 2024-09-07 18:20:14 字数 339 浏览 2 评论 0原文

我想知道 Location.distanceTo 方法在近似位置时是否会使用 Location 对象的精度字段,或者我是否必须自己将错误添加到这些字段中。用途是将距离与接近值进行比较。

Float dist=currentLocation.distanceTo(loc2);

这是

if (dist<100meters)

或者

if (dist+currentLocation.getAccuracy()+loc2.getAccuracy()<100meters)

I am wondering if the Location.distanceTo method will use the accuracy field of the Location object when approximates the location, or do I have to add by my own the errors to these fields. The usage is to compare the distance against a proximity value.

Float dist=currentLocation.distanceTo(loc2);

Would this be

if (dist<100meters)

or

if (dist+currentLocation.getAccuracy()+loc2.getAccuracy()<100meters)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不甘平庸 2024-09-14 18:20:14

看起来它忽略了准确性:
https: //android.googlesource.com/platform/frameworks/base/+/donut-release/location/java/android/location/Location.java#400

 400     /**
 401      * Returns the approximate distance in meters between this
 402      * location and the given location.  Distance is defined using
 403      * the WGS84 ellipsoid.
 404      *
 405      * @param dest the destination location
 406      * @return the approximate distance in meters
 407      */
 408     public float distanceTo(Location dest) {
 409         // See if we already have the result
 410         synchronized (mResults) {
 411             if (mLatitude != mLat1 || mLongitude != mLon1 ||
 412                 dest.mLatitude != mLat2 || dest.mLongitude != mLon2) {
 413                 computeDistanceAndBearing(mLatitude, mLongitude,
 414                     dest.mLatitude, dest.mLongitude, mResults);
 415                 mLat1 = mLatitude;
 416                 mLon1 = mLongitude;
 417                 mLat2 = dest.mLatitude;
 418                 mLon2 = dest.mLongitude;
 419                 mDistance = mResults[0];
 420                 mInitialBearing = mResults[1];
 421             }
 422             return mDistance;
 423         }
 424     }

It looks like it ignores accuracy:
https://android.googlesource.com/platform/frameworks/base/+/donut-release/location/java/android/location/Location.java#400

 400     /**
 401      * Returns the approximate distance in meters between this
 402      * location and the given location.  Distance is defined using
 403      * the WGS84 ellipsoid.
 404      *
 405      * @param dest the destination location
 406      * @return the approximate distance in meters
 407      */
 408     public float distanceTo(Location dest) {
 409         // See if we already have the result
 410         synchronized (mResults) {
 411             if (mLatitude != mLat1 || mLongitude != mLon1 ||
 412                 dest.mLatitude != mLat2 || dest.mLongitude != mLon2) {
 413                 computeDistanceAndBearing(mLatitude, mLongitude,
 414                     dest.mLatitude, dest.mLongitude, mResults);
 415                 mLat1 = mLatitude;
 416                 mLon1 = mLongitude;
 417                 mLat2 = dest.mLatitude;
 418                 mLon2 = dest.mLongitude;
 419                 mDistance = mResults[0];
 420                 mInitialBearing = mResults[1];
 421             }
 422             return mDistance;
 423         }
 424     }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文