为什么 turfjs 距离 returns 结果不同于 Google 地图几何库 computeDistanceBetween?

Why turfjs distance returns results different from Google Map geometry libs computeDistanceBetween?

我对为什么这两个库提供不同的结果感到困惑。

const CATA = {
  lat: 57.312004,
  lng: 25.289825
};

const PK = {
  lat: 57.307953,
  lng: 25.295025
};

const tCATA = turf.point([CATA.lat, CATA.lng]);
const tPK = turf.point([PK.lat, PK.lng]);
const tDistance = turf.distance(tCATA, tPK, { units: "meters" });

const gCATA = new google.maps.LatLng(CATA);
const gPK = new google.maps.LatLng(PK);
const gDistance = google.maps.geometry.spherical.computeDistanceBetween(
  gCATA,
  gPK
);

console.log(tDistance, gDistance); // 707.249063108749, 548.7294775022126

代码沙箱:https://codesandbox.io/s/boring-hawking-b7uwh

好吧,一件事可能是 turfjs 使用不同的地球半径 (6371008.8) 与 Google (6378137)。但即使为 computeDistanceBetween 提供草坪半径,结果仍然有 ~150 米的差异。

但是,假设 computeDistanceBetween 尊重半径参数,我假设 Google 也依赖于 Haversine,就像 turf 一样...

如果使用得当,这两个函数实际上 return 具有相同的值!

显然,turfjs - 因为它基于 GeoJSON - 使用 LngLat 阵型而不是 LatLng。在 turf.point 定义中切换它们可以解决问题并修复我拥有的所有相关内容。

供参考:https://macwright.org/lonlat/

A frustrating inconsistency in geospatial (mapping) software is coordinate order. Coordinates are often represented as arrays, like [-87.73, 41.83], instead of objects, like { lng: -87.73, lat: 41.83 }. This leaves it up to the developer to determine whether -87.73 is the longitude or latitude. One choice places a point on Chicago, and the other a location deep in Antarctica.

There's some consensus growing around longitude, latitude order for geospatial formats, but still chaos for libraries and software. It's up to the developer to be aware of this issue and read the requisite documentation, and flip coordinates if necessary to translate between different systems.