我想在Great Circle Method上计算从A点到B点的初始方位。我从网站上得到的javascript原型:
var y = Math.sin(λ2-λ1) * Math.cos(φ2);
var x = Math.cos(φ1)*Math.sin(φ2) -
Math.sin(φ1)*Math.cos(φ2)*Math.cos(λ2-λ1);
var brng = Math.atan2(y, x).toDegrees();
其中: λ=经度 φ=纬度
所以我尝试使用这样的HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<script>
function bearing()
{
if (typeof(Number.prototype.toDegrees) === "undefined")
{
Number.prototype.toDegrees = function()
{
return this * 180 / Math.PI;
}
}
var getlat1 = document.getElementById("lat1").value;
var getlong1 = document.getElementById("long1").value;
var getlat2 = document.getElementById("lat2").value;
var getlong2 = document.getElementById("long2").value;
var lat1 = parseFloat(getlat1);
var long1 = parseFloat(getlong1);
var lat2 = parseFloat(getlat2);
var long2 = parseFloat(getlong2);
var y = Math.sin(long2-long1) * Math.cos(lat2);
var x = Math.cos(lat1)*Math.sin(lat2) -
Math.sin(lat1)*Math.cos(lat2)*Math.cos(long2-long1);
var brng = Math.atan2(y, x).toDegrees();
document.getElementById('bearing').innerHTML = brng;
return brng;
}
</script>
</head>
<form action="#" onsubmit="bearing(); return false;">
<p>
Location 1 :
<input type="text" name="lat1" id="lat1" size="40" />
<input type="text" name="long1" id="long1" size="40" />
</p>
<p>
Location 2 :
<input type="text" name="lat2" id="lat2" size="40" />
<input type="text" name="long2" id="long2" size="40" />
</p>
<p>
<input type="submit" name="find" value="Search" />
</p>
</form>
Distance : <p id="results"></p>
<br />
Bearing : <p id="bearing"></p>
我的位置输入1 =&gt;纬度= -7.2742174&amp; longtitude = 112.719087和 我对位置2的输入=&gt;纬度= -7.586675&amp; longtitude = 112.8082266
但问题是,我页面上的结果是175.63821414343275。此外,正确答案是164.21。 任何人,你知道我的程序错误是什么吗?感谢..