开发者

google maps api v3 - nearest streetview

When streetview is not available for a certain location, I would like to find the nearest possible location with streetview?

The only way I could think of is.

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 f开发者_StackOverflow社区or point)
          bingo, break;
    }

    break if bingo;

    noOfPOints = noOfPoints+1;

}

But this is ridiculously expensive even if I want to find streetview within a 10-mile radius and I am counting on luck to find streetview at one of these points, i.e, I could just miss an actual point with streetview.

can somebody please direct me towards a better approach??


You can try to use the StreetViewService to help you find a nearest existing street view:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜