How to detect enter and exit streetView in Google Maps API v3

不问归期 提交于 2019-12-04 08:30:42

Observe the visible_changed-event of the streetView, the visible-property will be true or false (open or closed)

      function initialize() {
        var mapOptions = {
          center: new google.maps.LatLng(52.5498783, 13.425209),
          zoom: 8
        };
        var map = new google.maps.Map(document.getElementById("map-canvas"),
            mapOptions);
        google.maps.event.addListener(map.getStreetView(),'visible_changed',function(){
           alert('streetview is ' +(this.getVisible()?'open':'closed'));
        });
      }
      google.maps.event.addDomListener(window, 'load', initialize);
      html,body,#map-canvas { height: 100%; margin: 0; padding: 0; }
<script src="https://maps.googleapis.com/maps/api/js?v=3&.js"></script>
<div id="map-canvas"></div>

You have to use the visible_changed event listener and also add a doAlert() function. This would enable the street view to make an alert on entry for the street view and also while exitting the street view.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!