OpenLayers 计算两个坐标之间的距离给出了错误的答案
OpenLayers Caculate distance between two coordinates gives wrong answer
我有一个 GPX 文件,我正在尝试使用以下函数计算两点之间的总距离
import { LineString } from 'ol/geom'
getDistance(previous, next){
const coords = [ previous, next ]
const line = new LineString(coords);
return line.getLength();
},
我知道 getLength()
应该 return 以米为单位,但我得到的数字非常小,当我添加所有距离时,我离 gpx 文件的 2.6 公里还很远。
我的数据是这样的:[[0.194655, 38.730435], [0.194435, 38.730522]]
我得到的距离是 0.0002365776828023007
输出对我来说似乎是正确的,它是线串的长度(以度为单位)。
要获得以米为单位的距离,请尝试 getDistance
或 ol.Sphere
https://openlayers.org/en/latest/apidoc/module-ol_sphere.html#.getDistance
编辑:您将 LineString 的 getLength
方法与 ol.sphere
的 getLength
方法混淆了
我有一个 GPX 文件,我正在尝试使用以下函数计算两点之间的总距离
import { LineString } from 'ol/geom'
getDistance(previous, next){
const coords = [ previous, next ]
const line = new LineString(coords);
return line.getLength();
},
我知道 getLength()
应该 return 以米为单位,但我得到的数字非常小,当我添加所有距离时,我离 gpx 文件的 2.6 公里还很远。
我的数据是这样的:[[0.194655, 38.730435], [0.194435, 38.730522]]
我得到的距离是 0.0002365776828023007
输出对我来说似乎是正确的,它是线串的长度(以度为单位)。
要获得以米为单位的距离,请尝试 getDistance
或 ol.Sphere
https://openlayers.org/en/latest/apidoc/module-ol_sphere.html#.getDistance
编辑:您将 LineString 的 getLength
方法与 ol.sphere
getLength
方法混淆了