TurfJS Along Method 未按预期工作

TurfJS Along Method not working as expected

我对 turfJS 的 along() 方法有疑问。看来turfJS对我的坐标有问题。

var alongLine = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "LineString",
    "coordinates": [
      [-37.86902659740041, 144.6185302734375],
      [-37.86902659740041, 145.57159423828125]
    ]
  }
};

var newPoint = Turf.along(alongLine, 1, 'miles');
console.log('Walked 1 miles', newPoint);

代码是 运行 这是我得到的控制台日志:

  Walked 1 miles { type: 'Feature',
geometry: { 
  type: 'Point',
  coordinates: [ -37.86902659740041, 35.367001095372345 ] },
  properties: {} 
}

如您所见,坐标为-37。和 35。但是当沿着这条线(即 -37 和 145)走 1 英里时,我不明白为什么它是这么远的点(它就像距离这条线的地球的一半!)。

在 TurfJS 的文档中使用测试坐标时,它似乎工作正常,但我的坐标却坏了。这怎么可能?

您可以在此处找到带有示例的文档: http://turfjs.org/static/docs/module-turf_along.html

使用他们的示例坐标时

[-77.031669, 38.878605],
[-77.029609, 38.881946],
...

结果是(即使只使用 2 个点并且使用不到一英里:返回的始终是正确的点):

Walked 1 miles { type: 'Feature',
geometry: { 
  type: 'Point',
  coordinates: [ -77.02417351582903, 38.885335546214506 ] },
  properties: {} 
}

您的坐标对顺序错误。 GeoJSON 需要 [longitude, latitude] 坐标对的顺序。

这是 GeoJSON 规范:http://geojson.org/geojson-spec.html

这是坐标对排序的方便参考:http://www.macwright.org/lonlat/

这是一个可以用来快速可视化 GeoJSON 的网站:http://geojson.io/