为什么 SphericalUtil.computeDistanceBetween 方法没有 return 准确的结果?
Why SphericalUtil.computeDistanceBetween method does not return accurate result?
您好,我正在计算距任何路线最近点的距离。我正在测试 2 条路线(折线)。路线相对于原点的最近点几乎在同一坐标或地点但SphericalUtil.computeDistanceBetween方法google映射android库returns结果非常不同。
根据我的代码示例:
for(Route route : routes){
boolean isLocationOnEdge = PolyUtil.isLocationOnEdge(location, route.getLatLngCoordinates(), true, ROUTE_SEARCH_RADIUS);
boolean isLocationOnPath = PolyUtil.isLocationOnPath(location, route.getLatLngCoordinates(), true, ROUTE_SEARCH_RADIUS);
if(isLocationOnEdge || isLocationOnPath){
//meaning this route is near at the and compute distance from origin
LatLng nearestPoint = findNearestPoint(location, route.getLatLngCoordinates());
double distance = SphericalUtil.computeDistanceBetween(location, nearestPoint);
Log.i(TAG, "origin: "+location);
Log.i(TAG, "nearest point: "+nearestPoint);
Log.i(TAG, "distance: "+distance);
route.setDistanceFromOrigin(distance);
route.setNearestPointFromOrigin(nearestPoint);
nearRoutes.add(route);
}
}
日志中的结果如下:
origin: lat/lng: (7.0792276,125.6248482)
nearest point: lat/lng: (7.079228237884086,125.6248559529709)
distance: 0.8584555298849629
origin: lat/lng: (7.0792276,125.6248482)
nearest point: lat/lng: (7.0792199725865546,125.62475406260717)
distance: 10.422383454451605
如您所见,即使它们具有几乎相同的最近点,但两个距离之间存在很大差异。 (请看下面强调的比较)
路线A
来源:lat/lng:(7.0792276,125.6248482)
最近点:lat/lng:(7.079228237884086,125.6248559529709)
距离:0.8584555298849629
路线B
来源:lat/lng:(7.0792276,125.6248482)
最近点:lat/lng:(7.0792199725865546,125.62475406260717)
距离:10.422383454451605
为了说明,我绘制了 polygons/routes 及其最近的原点。我根据 logcat 中的代码记录的结果突出显示并指出了距离。为什么 Route A 到起点的距离(红线)最近点与 [=] 的距离(绿线)相比只是 0.8584555298849629 45=]路线 B 即 10.422383454451605?根据最近点的位置和坐标,它们彼此接近,因此它们的距离应该相差不大。
这让我有点困惑。我是不是遗漏了什么或者我的代码有问题?
没有证据表明 SphericalUtil
返回的信息不准确。
这张地图绘制了原点和您提到的两个点:
您可以在图片底部看到地图的比例尺。如果那么多像素是五英尺,那么两个 "nearest" 点看起来相距大约 11 米,这正是您的程序输出所说的。
您好,我正在计算距任何路线最近点的距离。我正在测试 2 条路线(折线)。路线相对于原点的最近点几乎在同一坐标或地点但SphericalUtil.computeDistanceBetween方法google映射android库returns结果非常不同。
根据我的代码示例:
for(Route route : routes){
boolean isLocationOnEdge = PolyUtil.isLocationOnEdge(location, route.getLatLngCoordinates(), true, ROUTE_SEARCH_RADIUS);
boolean isLocationOnPath = PolyUtil.isLocationOnPath(location, route.getLatLngCoordinates(), true, ROUTE_SEARCH_RADIUS);
if(isLocationOnEdge || isLocationOnPath){
//meaning this route is near at the and compute distance from origin
LatLng nearestPoint = findNearestPoint(location, route.getLatLngCoordinates());
double distance = SphericalUtil.computeDistanceBetween(location, nearestPoint);
Log.i(TAG, "origin: "+location);
Log.i(TAG, "nearest point: "+nearestPoint);
Log.i(TAG, "distance: "+distance);
route.setDistanceFromOrigin(distance);
route.setNearestPointFromOrigin(nearestPoint);
nearRoutes.add(route);
}
}
日志中的结果如下:
origin: lat/lng: (7.0792276,125.6248482)
nearest point: lat/lng: (7.079228237884086,125.6248559529709)
distance: 0.8584555298849629
origin: lat/lng: (7.0792276,125.6248482)
nearest point: lat/lng: (7.0792199725865546,125.62475406260717)
distance: 10.422383454451605
如您所见,即使它们具有几乎相同的最近点,但两个距离之间存在很大差异。 (请看下面强调的比较)
路线A
来源:lat/lng:(7.0792276,125.6248482)
最近点:lat/lng:(7.079228237884086,125.6248559529709)
距离:0.8584555298849629
路线B
来源:lat/lng:(7.0792276,125.6248482)
最近点:lat/lng:(7.0792199725865546,125.62475406260717)
距离:10.422383454451605
为了说明,我绘制了 polygons/routes 及其最近的原点。我根据 logcat 中的代码记录的结果突出显示并指出了距离。为什么 Route A 到起点的距离(红线)最近点与 [=] 的距离(绿线)相比只是 0.8584555298849629 45=]路线 B 即 10.422383454451605?根据最近点的位置和坐标,它们彼此接近,因此它们的距离应该相差不大。
这让我有点困惑。我是不是遗漏了什么或者我的代码有问题?
没有证据表明 SphericalUtil
返回的信息不准确。
这张地图绘制了原点和您提到的两个点:
您可以在图片底部看到地图的比例尺。如果那么多像素是五英尺,那么两个 "nearest" 点看起来相距大约 11 米,这正是您的程序输出所说的。