以下代码中发生了什么

时间:2011-08-21 15:29:06

标签: javascript google-maps google-maps-api-3

任何人都可以告诉我以下代码中发生了什么吗?我正在努力完成一个教程,我有点迷失。

我不确定如何调用以下函数或如何设置参数(例如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

中找到

2 个答案:

答案 0 :(得分:1)

不知道你是否曾经编过JS,但是你必须创建一个代表你类的函数......

function LatLon(lat, lon, rad) {

如果你写了这个,你可以通过输入

来调用这个“构造函数”
var myLatLon = new LatLon(lat, lon, rad)

加上之前的相同!

答案 1 :(得分:0)

你可以这样称呼

var myLatLon = new LatLon();
maLatLon.destinationPoint(45, 1);
你读过这个了吗??

http://en.wikipedia.org/wiki/Great_circle

你想知道每一行做什么或想知道什么是计算的目的是什么?

相关问题