How to check if Google Street View available and display message?

后端 未结 3 1397
刺人心
刺人心 2020-12-01 05:46

I am passing lat and lng variables and display google sreet view in a div. The problem is that when the StreetView is unavilable then nothing is displayed. I would like to c

3条回答
  •  难免孤独
    2020-12-01 06:25

    Update for Google Maps JavaScript API v3.25+: In v3.25 (current release version) and v3.26 (current experimental version), getPanoramaByLocation() is still available but not documented anymore.

    @arthur-clemens's accepted answer still works, but use getPanorama() with a StreetViewLocationRequest instead if you want better compatibility:

    var gstService = new google.maps.StreetViewService();
    
    gstService.getPanorama({
        location: new google.maps.LatLng(40.7140, -74.0062),
        source: google.maps.StreetViewSource.OUTDOOR
    }, function (data, status) {
        if (status === google.maps.StreetViewStatus.OK) {
            // OK
        } else {
            // error or no results
        }
    });
    

    Omit source in the StreetViewLocationRequest if you do not want the panorama search to be limited to outdoor ones.

提交回复
热议问题