detecting “we have no imagery” of google maps street view static images

后端 未结 6 1711
梦毁少年i
梦毁少年i 2021-02-13 17:43

I\'m generating street view static images like so:

https://maps.googleapis.com/maps/api/streetview?size=1080x400&location=%s&fov=90&heading=235&pitch=0&a

6条回答
  •  不思量自难忘°
    2021-02-13 18:43

    Request a google street view image and if it has a specific file size it is a 'Not street view avaible'. I did the follwing:

    var url = 'google street view url';
    
    var xhr = new XMLHttpRequest();
    xhr.open('GET', url, true);
    xhr.responseType = 'blob';
    
    xhr.onload = function (e) {
      if (this.status == 200) {
        try {
          var image = new Blob([this.response], {type: 'image/jpeg'});
    
          if (image.size) {
            if (url.indexOf('640x640') > -1 && image.size === 8410) {
              // Not street view
            }
    
            if (url.indexOf('400x300') > -1 && image.size === 3946) {
               // Not street view
            }
          }
        } catch (err) {
          // IE 9 doesn't support blob
        }
      }
    };
    
    xhr.send(); 
    

提交回复
热议问题