【发布时间】:2011-10-31 15:17:21
【问题描述】:
谁能告诉我下面的代码发生了什么?我正在尝试完成教程,但我有点迷失了。
我不确定如何调用以下函数,或者如何设置参数(例如if brng =45 and dist=1。
LatLon.prototype.destinationPoint = function(brng, dist) {
dist = typeof(dist)=='number' ? dist : typeof(dist)=='string' && dist.trim()!='' ? +dist : NaN;
dist = dist/this._radius; // convert dist to angular distance in radians
brng = brng.toRad(); //
var lat1 = this._lat.toRad(), lon1 = this._lon.toRad();
var lat2 = Math.asin( Math.sin(lat1)*Math.cos(dist) +
Math.cos(lat1)*Math.sin(dist)*Math.cos(brng) );
var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(dist)*Math.cos(lat1),
Math.cos(dist)-Math.sin(lat1)*Math.sin(lat2));
lon2 = (lon2+3*Math.PI)%(2*Math.PI) - Math.PI; // normalise to -180...+180
return new LatLon(lat2.toDeg(), lon2.toDeg());
}
此代码可以在以下页面找到http://www.movable-type.co.uk/scripts/latlong.html
【问题讨论】:
-
我看到一大堆可怕的变量名选择和一般不可读的代码。
-
你尝试了什么?
destinationPoint(45, 1)怎么样? -
怎么样...真的,这很简单。 @Shaheryar,您真的只需要尝试一下,而不是指望我们会在您输入每个字符的过程中让您放心。
-
@JamWaffles 我不会问你如果我自己知道以下代码中发生了什么,我作为参考给出了我从中获取此代码的网站的链接。这段代码的作用是,如果你给出起点坐标以及方位和距离,它会给你终点坐标。但我不知道这段代码是如何工作的。
-
“以下代码中发生了什么”是什么意思?您需要为这个问题添加一些上下文,否则它很可能会被关闭。
标签: javascript google-maps google-maps-api-3