如何使用经纬度坐标计算谷歌地图上两条路径线之间的角度 [英] how to calculate angle between two path lines on google map using lat-long coordinates

查看:639
本文介绍了如何使用经纬度坐标计算谷歌地图上两条路径线之间的角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算Google地图上两条路径线之间的角度。我有线的终点的经纬度坐标。
请建议如果有其他信息我可以用它来做到这一点,可以从谷歌地图。

解决方案

如果距离很小,你可以使用这种方法。
距离越远,越远离赤道,准确度就越低。
首先使用 computeHeading()

computeHeading(from:LatLng,to:LatLng)。将标题从一个LatLng返回到另一个LatLng。标题以[-180,180]范围内的北方顺时针方向表示。

 函数getBearings(){
var spherical = google.maps.geometry.spherical;
var point1 = markers [0] .getPosition(); //点1的位置
var point2 = markers [1] .getPosition();
var point3 = markers [2] .getPosition();
var bearing1 = google.maps.geometry.spherical.computeHeading(point1,point2);
var bearing2 = google.maps.geometry.spherical.computeHeading(point2,point3);
var angle = getDifference(bearing1,bearing2);
回报角度;
}

然后,您可以使用此函数计算方位角。

  function getDifference(a1,a2){
al =(a1> 0)? a1:360 + a1;
a2 =(a2> 0)? a2:360 + a2;
var angle = Math.abs(a1-a2)+180;
if(angle> 180){
angle = 360 - angle;
}
return Math.abs(angle);
}


I want to calculate angle between two path lines on Google map. I have the lat-long coordinates of the end points of the lines. Please suggest If there is other information I can use to do this that is available from Google maps.

If the distances are small you can use this method. The accuracy reduces with large distances and the further you move from the equator. First find bearings with computeHeading()

computeHeading(from:LatLng, to:LatLng) .Returns the heading from one LatLng to another LatLng. Headings are expressed in degrees clockwise from North within the range [-180,180).

function getBearings(){
    var spherical = google.maps.geometry.spherical; 
    var point1 = markers[0].getPosition();// latlng of point1
    var point2 = markers[1].getPosition();
    var point3 = markers[2].getPosition();
    var bearing1 = google.maps.geometry.spherical.computeHeading(point1,point2);
    var bearing2 = google.maps.geometry.spherical.computeHeading(point2,point3);
    var angle =getDifference(bearing1, bearing2);
    return angle;
}

You can then use this function to calculate angle between the bearings.

function getDifference(a1, a2) {
    al = (a1>0) ? a1 : 360+a1;
    a2 = (a2>0) ? a2 : 360+a2;
    var angle = Math.abs(a1-a2)+180;
    if (angle > 180){
        angle = 360 - angle;
    }
   return   Math.abs(angle);
}

这篇关于如何使用经纬度坐标计算谷歌地图上两条路径线之间的角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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