【问题标题】:OpenLayers Caculate distance between two coordinates gives wrong answerOpenLayers 计算两个坐标之间的距离给出错误答案
【发布时间】:2020-12-17 14:27:21
【问题描述】:

我有一个 GPX 文件,我正在尝试使用以下函数计算两点之间的总距离

import { LineString } from 'ol/geom'

getDistance(previous, next){
   const coords = [ previous, next ]
   const line = new LineString(coords);
   return line.getLength();
},

我知道getLength() 应该以米为单位返回,但我得到了一些非常小的数字,当我添加所有距离时,我离 gpx 文件的 2.6 公里还很远。

我的数据看起来像这样:[[0.194655, 38.730435], [0.194435, 38.730522]],我为此得到的距离是0.0002365776828023007

【问题讨论】:

    标签: openlayers


    【解决方案1】:

    输出对我来说似乎是正确的,它是以度为单位的线串长度。

    要获得以米为单位的距离,请尝试getDistance of ol.Sphere

    https://openlayers.org/en/latest/apidoc/module-ol_sphere.html#.getDistance

    编辑:您将 LineString 的 getLength 方法与 ol.sphere 的 getLength 方法混淆了

    【讨论】:

      猜你喜欢
      • 2020-02-12
      • 2018-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-12
      • 2016-07-16
      • 1970-01-01
      相关资源
      最近更新 更多