google maps api v3 - nearest streetview

前端 未结 1 1155
挽巷
挽巷 2021-02-02 17:02

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.



        
相关标签:
1条回答
  • 2021-02-02 17:46

    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 讨论(0)
提交回复
热议问题