如何将距离从度转换为米? [英] How to transform a distance from degrees to metres?
问题描述
我将OpenLayers与普通的墨卡托地图一起使用,并且试图通过在latlong中找到点网格来对边界框进行采样. bbox用latlon表示,例如
I'm using OpenLayers with an ordinary mercator map and I'm trying to sample a bounding box by finding a grid of points in latlong. The bbox is expressed in latlon, e.g.
48.1388,-15.3616,55.2057,-3.9359
我可以以度来定义距离(例如x:2.5,y:2.4),然后从那里计算出点. 但我想用米(例如50000)表示该距离,以便将其与用户的思维方式(人们理解米而不是度)联系起来. 如何转换此距离?我知道如何重新投影一个点,而不是一个距离.
I can define a distance in degrees (e.g. x: 2.5, y: 2.4) and work out the points from there. But I'd like to express this distance in metres (e.g. 50000) in order to relate it to the user mindset (people understand metres, not degrees). How can I convert this distance? I know how to reproject a point, but not a distance.
感谢您的任何提示! Mulone
Thanks for any hints! Mulone
推荐答案
使用 haversine公式来获取两者之间的距离纬度/经度两点.假定地球是一个球体(在大多数情况下,它是足够好"的).
Use the haversine formula to get the distance between two points of lat/long. This assumes the earth is a sphere (which is, for most cases, "good enough").
它的Javascript实现(从此处偷偷地偷了)看起来像这样:
A Javascript implementation of it (shamelessly stolen from here) looks like this:
var R = 6371; // km
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad();
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
这篇关于如何将距离从度转换为米?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!