I've got a webapp that uses Google Maps JavaScript API V3 to display a regular googlemap and a StreetView side by side. When the map changes position, it tells the streetview to follow it using StreetViewPanorama.setPosition().
However, when I scroll the map to someplace where StreetView is not available, the streetview image stays stuck开发者_StackOverflow中文版 at the last location. Its getPosition() method returns the same LatLng as the master map.
How can I tell if I have moved to a place where StreetView is not available?
OK, I found an answer, if not the answer.
After each move, use StreetViewService.getPanoramaByLocation() to get the nearest panorama within N meters. Based on that you can stay where you are, move, or setVisible(false).
I used a flag and a setTimer to prevent lots of unnecessary calls to getPanoramaByLocation like this:
var check_availability_lock = false;
var check_availability = function() {
    if (check_availability_lock) {
        return;
    }
    check_availability_lock = true;
    var availability_cb = function(data, status) {
        check_availability_lock = false;
        // console.log("status = ", status);
        if (status !== 'OK') {
            map.setVisible(false);
        }
        else {
            map.setVisible(true);
        }
    }
    setTimeout(function(){
        var latlng = map.getPosition();
        svc.getPanoramaByLocation(latlng, 50, availability_cb);
    }, 2000);
};
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论