4

我想明確定義Google地圖LatLngBounds物體爲距離P右側x海里約x海里,並將LatLngBounds定義爲是點P和y納米以下P.ý海里以上使用谷歌地圖將海里轉換爲經度給定緯度

所以基本上我想要定義使用緯度和經度的LatLngBounds,我想從X,Y的是緯度和經度,和P.

度緯度很容易轉換爲經度:1度等於一海里。但是,
每度經度隨緯度變化。其計算公式是(在php)

public static function degPerNmAtLat($lat) { 
    $pi80 = M_PI/180; 
    $lat = $lat*$pi80; //convert lat to radians 
    $p1 = 111412.84;  // longitude calculation term 1 
    $p2 = -93.5;   // longitude calculation term 2 
    $p3 = 0.118;   // longitude calculation term 3 
    // below: calculate the length of a degree of latitude and longitude in meters 
    $longlen = ($p1 * cos($lat)) + ($p2 * cos(3 * $lat)) + ($p3 * cos(5 * $lat)); 
    $longlen = $longlen * (3.280833333)/(5280 * 1.15077945); // convert to nautical miles 
    return 1/$longlen; 
} 

但是,這似乎是一個共同的任務,我想知道,如果谷歌地圖功能我缺少這將做到這一點。是否有本地Google地圖方式可以在不使用上述公式的情況下從x,y和P創建我的LatLngBounds對象?

回答

3

你可以在Google Maps API V3 geometry library使用computeOffset()功能:

var dist = nauticalMiles * 1852; // convert nm to meters 
var point = new google.maps.LatLng(lat,lng); 
var eastPoint = google.maps.geometry.spherical.computeOffset(point,dist,90.0); 
var westPoint = google.maps.geometry.spherical.computeOffset(point,dist,270.0); 
+0

是的,這是它。命名空間對象中的球形對象還有其他幾種有用的方法,例如兩個LatLng對象與標題之間的距離。謝謝。 – steampowered