gpt4 book ai didi

javascript - OpenLayers 2 : Unexpected results from Point. 距离()

转载 作者:行者123 更新时间:2023-12-03 05:06:04 28 4
gpt4 key购买 nike

我尝试使用 OpenLayers 2 来计算 GPS 轨迹的点之间的距离。我尝试使用 Point.distanceTo(),仅使用点,并将点转换为我的 map 。在这两种情况下,我都得到了一个我无法真正解释的结果:

var epsg4326 = new OpenLayers.Projection("EPSG:4326");
var pointA = new OpenLayers.Geometry.Point(5.339911, 60.371876);
var pointB= new OpenLayers.Geometry.Point(5.34003, 60.371471);
console.log("raw: " + pointA.distanceTo(pointB));

pointA = new OpenLayers.Geometry.Point(5.339911, 60.371876).transform(epsg4326, this.map.getProjectionObject());
pointB= new OpenLayers.Geometry.Point(5.34003, 60.371471).transform(epsg4326, this.map.getProjectionObject());
console.log("transformed: " + PointA.distanceTo(pointB));

给出以下输出:

raw: 0.0004221208357810271
transformed: 92.1524487013366

根据http://www.movable-type.co.uk/scripts/latlong.html结果应该是45.51 m,这与我的预期一致。

我是否做错了什么,或者结果是我不期望的?

最佳答案

尝试

 var line = new OpenLayers.Geometry.LineString([pointA, pointB]);
console.log("Distance: " +line.getGeodesicLength(epsg4326));

这给你 45,6(Google map 给你 46m)

-distanceTo 可用于平面测量(地球不是 falt :D)

Calculate the closest distance between two geometries (on the x-y plane). http://dev.openlayers.org/docs/files/OpenLayers/Geometry-js.html#OpenLayers.Geometry.distanceTo

希望这有帮助

关于javascript - OpenLayers 2 : Unexpected results from Point. 距离(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41996471/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com