2010-10-22 47 views
12

當街景不適用於某個位置時,我想找到最近的可能位置與街景?谷歌地圖api v3 - 最近的街景

我能想到的唯一方法就是。

radius = 0; 
noOfPoints = 3; 

while(radius < 10 miles){ 

    radius = radius + 0.2 miles 
    points = calculate 4 * noOfPoints at this radius 

    loop(points) 
    { 
     if(streetview visibile for point) 
      bingo, break; 
    } 

    break if bingo; 

    noOfPOints = noOfPoints+1; 

} 

但是,這是即使我想在10英里半徑內找到街景和我要靠運氣在這些點中的一個找到街景,即貴的離譜,我可能只是會錯過與實際點街景。

有人可以請直接指向我一個更好的方法?

回答

10

你可以嘗試使用StreetViewService幫助你找到最近的現有街道視圖:

var astorPlace = new google.maps.LatLng(40.729884, -73.990988); 
var webService = new google.maps.StreetViewService(); 
/**Check in a perimeter of 50 meters**/ 
var checkaround = 50; 
/** checkNearestStreetView is a valid callback function **/ 

webService.getPanoramaByLocation(astorPlace,checkaround ,checkNearestStreetView); 

function checkNearestStreetView(panoData){ 
    if(panoData){ 

     if(panoData.location){ 

      if(panoData.location.latLng){ 
       /**Well done you can use a nearest existing street view coordinates**/ 
      } 
     } 
    } 
    /** Else do something... **/ 
} 
+0

感謝Hakaesbe .. – user441660 2011-03-03 16:55:39

+2

這不會給最近的地方,以點:(如果定義半徑例如1000,那麼你會得到一個更遠的點... – Tiit 2013-02-22 10:14:43

+1

它不會給出最近的街景,半徑越大,你得到的街景越不準確 – 2014-08-18 04:33:42