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

后端 未结 3 1395
刺人心
刺人心 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:10

    In v3 this has changed a bit. Check out the documentation at http://code.google.com/apis/maps/documentation/javascript/reference.html#StreetViewService

    The updated code is:

    var streetViewService = new google.maps.StreetViewService();
    var STREETVIEW_MAX_DISTANCE = 100;
    var latLng = new google.maps.LatLng(40.7140, -74.0062);
    streetViewService.getPanoramaByLocation(latLng, STREETVIEW_MAX_DISTANCE, function (streetViewPanoramaData, status) {
        if (status === google.maps.StreetViewStatus.OK) {
            // ok
        } else {
            // no street view available in this range, or some error occurred
        }
    });
    

提交回复
热议问题