【问题标题】:Disable indoor view of buildings in Google Maps Street View在 Google Maps Street View 中禁用建筑物的室内视图
【发布时间】:2015-11-22 06:46:21
【问题描述】:

我正在开发一个项目,该项目在 Google 地图上显示一堆标记,并允许用户搜索并获取有关位置的相关信息。我没有禁用街景,因为我想让用户能够从外面看到建筑物。

但是,对于某些位置,当进入街景模式时,Google 地图会立即显示相邻商家的室内情况。我想要的是能够在我的应用程序上完全禁用室内视图。

是否有人知道 Google Maps API 中的某个设置可以做到这一点,或者可能是一个聪明的黑客来解决这个问题?老实说,我没有发现任何东西。

【问题讨论】:

    标签: google-maps google-maps-api-3 google-street-view


    【解决方案1】:

    在实验版本(当前 v=3.21)中,现在有一个 StreetViewSource 可以在 StreetViewLocationRequest 中提供

    StreetViewSource

    google.maps.StreetViewSource 类 将街景搜索限制为选定来源的标识符。 持续的 DEFAULT 使用街景的默认来源,搜索将不限于特定来源。 OUTDOOR 将街景搜索仅限于户外收藏。

    代码 sn-p(带有source: OUTDOOR):

    /*
     * Click the map to set a new location for the Street View camera.
     */
    
    var map;
    var panorama;
    
    function initMap() {
      var myLatlng = new google.maps.LatLng(51.343364, 12.378962999999999);
      var sv = new google.maps.StreetViewService();
    
      panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'));
    
      // Set up the map.
      map = new google.maps.Map(document.getElementById('map'), {
        center: myLatlng,
        zoom: 16,
        streetViewControl: false
      });
    
      // Set the initial Street View camera to the center of the map
      sv.getPanorama({
        location: myLatlng,
        radius: 50,
        source: google.maps.StreetViewSource.OUTDOOR
      }, processSVData);
    
      // Look for a nearby Street View panorama when the map is clicked.
      // getPanoramaByLocation will return the nearest pano when the
      // given radius is 50 meters or less.
      map.addListener('click', function(event) {
        sv.getPanorama({
          location: event.latLng,
          radius: 50
        }, processSVData);
      });
    }
    
    function processSVData(data, status) {
      if (status === google.maps.StreetViewStatus.OK) {
        var marker = new google.maps.Marker({
          position: data.location.latLng,
          map: map,
          title: data.location.description
        });
    
        panorama.setPano(data.location.pano);
        panorama.setPov({
          heading: 270,
          pitch: 0
        });
        panorama.setVisible(true);
    
        marker.addListener('click', function() {
          var markerPanoID = data.location.pano;
          // Set the Pano to use the passed panoID.
          panorama.setPano(markerPanoID);
          panorama.setPov({
            heading: 270,
            pitch: 0
          });
          panorama.setVisible(true);
        });
      } else {
        console.error('Street View data not found for this location.');
      }
    }
    google.maps.event.addDomListener(window, 'load', initMap);
          html,
          body {
            height: 100%;
            margin: 0;
            padding: 0;
          }
          #map {
            height: 100%;
          }
    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
    <div id="map" style="width: 45%; height: 100%;float:left"></div>
    <div id="pano" style="width: 45%; height: 100%;float:left"></div>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-27
      • 1970-01-01
      相关资源
      最近更新 更多