2011-04-16 24 views
1

我在閱讀:http://www.panoramio.com/api/widget/api.html#photo-widget構建一個JavaScript照片小部件。獲取給定的一個經度和一個經度的四個點的矩形只有

Request - >request object表,它寫的是:

名稱:rect

例如值:{'sw': {'lat': -30, 'lng': 10.5}, 'ne': {'lat': 50.5, 'lng': 30}}

含義:This option is only valid for requests where you do not use the ids option. It indicates that only photos that are in a certain area are to be shown. The area is given as a latitude-longitude rectangle, with sw at the south-west corner and ne at the north-east corner. Each corner has a lat field for the latitude, in degrees, and a lng field for the longitude, in degrees. Northern latitudes and eastern longitudes are positive, and southern latitudes and western longitudes are negative. Note that the south-west corner may be more "eastern" than the north-east corner if the selected rectangle crosses the 180° meridian

但通常我們只給出一個緯度點和一個經度點。

我應該寫什麼樣的表情來構建上述四點,以覆蓋我手邊有兩點的區域周圍的圖片?

例如,我在巴黎:

緯度:48.8566667

LNG:2.3509871

我想捂住它周圍的圖片10公里矩形。

謝謝。

+0

可能DUP http://stackoverflow.com/questions/238260/how-to-calculate-the-bounding-box-for-a-given-lat-lng-location – kjy112 2011-04-16 14:15:04

+0

謝謝。它是。 – Victor 2011-04-16 14:26:32

回答

1

這是我從QuentinUK獲得的Panoramio Forum的答案。

不能做10公里的距離,因爲這意味着一個圓形區域。它只能做矩形。

所以你可能會近似(最好是使用Vincenty的公式)並計算一個角度+/-。

function requestAroundLatLong(lat,lng,km){ 
    // angle per km = 360/(2 * pi * 6378) = 0.0089833458 
    var angle=km* 0.0089833458; 
    var myRequest = new panoramio.PhotoRequest({ 
     'rect': {'sw': {'lat': lat-angle, 'lng': lng-angle}, 'ne': {'lat': lat+angle, 'lng': lng+angle}} 
     }); 
    return myRequest; 
    } 

var widget = new panoramio.PhotoWidget('wapiblock', requestAroundLatLong(48.8566667, 2.3509871,10), myOptions); 
1

如果你想使用REST API:

VAR Lattitude = 「48.8566667」; var Longitude =「2.3509871」;

var angle = km * 0.0089833458;

 testo.Text = "<script src=\"http://www.panoramio.com/map/get_panoramas.php?order=popularity&set=full&from=0&to=14&minx=" + clon - angle + "&miny=" + clat - angle + "&maxx=" + clon + angle + "&maxy=" + clat + angle + "&callback=mostrareFotos&size=medium\" type=\"text/javascript\"></script>"; 
相關問題