0

我正在尋找一個公式jquery/javascript我可以使用獲得新的座標,如果我有一個現有的經緯座標。我有幾個標記在谷歌地圖,我想分散他們一個分開的距離。jquery/JavaScript公式添加x米/英里/公里到latlng座標

我擁有的所有標記具有相同的經緯座標。我正在尋找Haversine公式但是我沒有看到任何公式可以給我從現有的一對lat長座標的新座標。

回答

0

http://www.movable-type.co.uk/scripts/latlong.html 

/** 
* Returns the destination point from this point having travelled the given distance (in km) on the 
* given initial bearing (bearing may vary before destination is reached) 
* 
* see http://williams.best.vwh.net/avform.htm#LL 
* 
* @param {Number} brng: Initial bearing in degrees 
* @param {Number} dist: Distance in km 
* @returns {LatLon} Destination point 
*/ 
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()); 
} 
發現這對一些研究
相關問題