Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Is there a way to detect when a user enters and exits StreetView in Google Maps under API v3?

I want to trigger an existing 'Hide Menu' function when the user enters StreetView (as the menu isn't relevant) and then re-show the menu when they exit.

like image 1000
Fat Monk Avatar asked Feb 28 '15 17:02

Fat Monk


1 Answers

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>
like image 183
Dr.Molle Avatar answered Nov 08 '22 15:11

Dr.Molle