openlayers - OpenLayers 计算两个坐标之间的距离给出了错误的答案
问题描述
我有一个 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
解决方案
输出对我来说似乎是正确的,它是以度为单位的线串长度。
要获得以米为单位的距离,请getDistance
尝试ol.Sphere
https://openlayers.org/en/latest/apidoc/module-ol_sphere.html#.getDistance
编辑:您将getLength
LineString 的getLength
方法与 ol.sphere的方法混淆了
推荐阅读
- android - Android Nativescript 应用程序在启动时崩溃
- javascript - Ionic/Angular Square 网络支付
- kotlin - Mockk 将重载函数与泛型匹配
- javascript - 通用联合类型的打字稿错误:'不可分配给类型'
- javascript - 如何让 Object.keys 遍历数组对象以在每次迭代结束时等待异步获取的 api 结果?
- rust - 在内部创建 tokio::runtime 的应用程序的异步集成测试失败,并显示“无法在运行时内启动运行时”
- python - 在 pandas 和 numpy 中构建具有多条件的新列
- android - 电子邮件和密码身份验证在 Android Studio 上不可见
- javascript - 西里尔文中的 \b 问题(JavaScript 正则表达式)
- java - 反编译 MinecraftForge 1.8.9 时出现 Java“peer not authenticated”错误