2011-03-07 48 views

回答

2

我不知道,這樣的功能是由谷歌地圖提供的,但數學會幫助你生存的真實的;)Calculate distance, bearing and more between Latitude/Longitude points是很好地參考了不同的地理數據計算。打開該頁面,然後轉到「目標點給定的距離和方位從起點」部分,有公式以及在線計算器,因此您可以檢查它們(以及您可以在地圖上看到的點)。公式有幾個參數:

(lat1,lng1) - your point (marker coordinates) 
d - distance (in your case it would be 2.5km) 
brng - angle.. 

找到束縛你需要找到南,北,東,西矩形兩側的座標,所以你會在參數改變一切的角度,對你來說這將是0, 90,180和270名學生。公式:

var lat2 = Math.asin(Math.sin(lat1)*Math.cos(d/R) + 
         Math.cos(lat1)*Math.sin(d/R)*Math.cos(brng)); 
var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(d/R)*Math.cos(lat1), 
          Math.cos(d/R)-Math.sin(lat1)*Math.sin(lat2)); 

嗯,指定角= 0,你找不着北,PI/2 - 東,PI - 南,3 * PI/2 - 西(角度應以弧度傳遞)。

R = earth’s radius (mean radius = 6,371km) 

ADD-ON:只是看着該網頁的源代碼,因爲當我在在線形式軸承進入= 0,距離= 2,那麼我看到映射與兩個點,並根據地圖比例尺他們之間的距離真的是2公里。那麼,你可以用一個簡單的attribution許可使用這個庫,不提供任何擔保明示或暗示的,只是它包含

<script src="http://www.movable-type.co.uk/scripts/latlon.js"></script> 

你需要的功能是:

/** 
* 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()); 
} 

,當我以在線的形式軸承進入= 0,距離= 2,這種方法與參數執行latLonCalc.destinationPoint(0, "2");

嘗試,否則給我輸入參數,以便我可以檢查出了什麼問題

UPDATE2該庫適用於Grads,並將它們轉換爲弧度進行計算,然後返回到梯度。剛進行的簡單測試:

var latLonCalc = new new LatLon(25, 45); 
var point = latLonCalc.destinationPoint(0, "2"); 
console.info(point); 
// prints 25°01′05″N, 045°00′00″E { _lat=25.01798643211838, _lon=45.00000000000005, _radius=6371} 

所以入口點到最終目的地的距離有點大於1分鐘;

earth = 2 * PI * 6371; // 40 009.98km 
=> 40 009.98km/360grad =~111.14 
=> 111,14/60 = 1.85 (km/minute) ~2km 

是次的運算,它告訴我,最後一點是,在不遠處則切入點,距離應2公里;)

+0

你確定這是100%正確的,如果我用上述公式brng = 0,距離= 2我得到一個超過2公里遠的地方 – nokiko

+0

@nokiko:我更新了我的答案,請看看 – Maxym