【问题标题】:How to calculate the distance of two points using coordinates?如何使用坐标计算两点的距离?
【发布时间】:2017-10-09 06:34:24
【问题描述】:

我有一个包含 100 条折线的 Geojson 文件, 例如:

{
  "type":"MultiLineString",
   "coordinates":
    [
     [
      [73.970889292119,15.272263607379],
      [73.970743508934,15.272184655773] 
    ]
   ]
}

如何以公里为单位计算折线的距离或如何在传单中计算相同的距离?

【问题讨论】:

标签: javascript php math leaflet geojson


【解决方案1】:

给定一组polylines,当我们知道坐标时,您可以应用math 公式来找出两个之间的距离 点。

let polylines=[{
  "type":"MultiLineString",
   "coordinates":
    [
     [
      [73.970889292119,15.272263607379],
      [73.970743508934,15.272184655773] 
    ]
   ]
},{
  "type":"MultiLineString2",
   "coordinates":
    [
     [
      [34.970889292119,15.272263607379],
      [67.970743508934,67.272184655773] 
    ]
   ]
}];
polylines=polylines.map(function(item){
  let latitude1=item.coordinates[0][0][0];
  let longitude1=item.coordinates[0][0][1];
  let latitude2=item.coordinates[0][1][0];
  let longitude2=item.coordinates[0][1][1];
  let distance=Math.sqrt(Math.pow((latitude1-latitude2),2)+Math.pow((longitude1-longitude2),2));
  return {type:item.type, distance:distance};
});
console.log(polylines);

【讨论】:

  • 你假设平面几何。请注意,GeoJSON 格式通常用于地球上的特征,即或多或少的球形几何体。
猜你喜欢
  • 2020-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-12
相关资源
最近更新 更多