OpenLayers 3:如何计算2点之间的距离? [英] OpenLayers 3: How to calculate distance between 2 points?

查看:540
本文介绍了OpenLayers 3:如何计算2点之间的距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用OpenLayers 3,如何确定球形墨卡托(SRID:3857)投影中两点之间的距离?

Using OpenLayers 3, how can I determine the distance between two points in the Spherical Mercator (SRID: 3857) projection?

我知道 distanceTo 在OpenLayers 2中使用

I know that distanceTo was used in OpenLayers 2

point1.distanceTo(point2)

我浏览了 OpenLayers 3文档,但我找不到类似的东西...

I looked through the OpenLayers 3 docs, but I'm not finding anything similar...

推荐答案

您可以使用Sphere对象计算两个坐标之间的距离,如下所示:

You can use the Sphere object to calculate the distance between two coordinates like this:

var distance = ol.sphere.WGS84.haversineDistance([0,0],[180,0]); 
//20037508.34 meters 

Sphere还提供各种算法来计算距离,如余弦,equirectangular等等。
您还可以创建半径为不同椭圆体的Sphere对象。

Sphere provides also various algorithms to calculate the distance like cosine,equirectangular etc. You can also create the Sphere object with the radius of a different ellipsoid.

我不知道为什么文档不在线,但是你可以检查球体对象源代码中可用的方法: https://github.com/openlayers/ol3/blob/master/src/ol/sphere.js

I don't know why the docs are not online, but you can check the methods available from the source code of the sphere object: https://github.com/openlayers/ol3/blob/master/src/ol/sphere.js

我个人认为看源头代码是查找OpenLayers3答案的最佳方式;)

I personally think that looking at the source code is the best way to find answers about OpenLayers3 ;)

这篇关于OpenLayers 3:如何计算2点之间的距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆