31

How do I know when the google map is in streetview mode or roadmap mode? Is there an event that gets fired? I tried looking through the docs, and there doesn't seem to be anything. Am I missing something?

When the user switches into streetview mode, I want the UI to change, but I don't know which event to bind to.

1 Answer 1

67

Detect the visible_changed event on the StreetViewPanorama associated with your Map object. You can get the panorama from the map by calling its getStreetView() method and bind the handler to that object's event. You will have to test the StreetViewPanorama's visibility by calling its getVisible() method.

For instance:

var map = new google.maps.Map(document.getElementById("theMap"), {streetViewControl: true});

var thePanorama = map.getStreetView();

google.maps.event.addListener(thePanorama, 'visible_changed', function() {

    if (thePanorama.getVisible()) {

        // Display your street view visible UI

    } else {

        // Display your original UI

    }

});

See the events section of the StreetViewPanorama Object Documentation for more events you can listen for on this object.

5
  • Yea I managed to figure it out late last night, thanks though :D
    – userinev
    Commented Aug 31, 2011 at 18:33
  • 1
    @userinev Doh, I posted this within 15 minutes of your asking, hehe. Too bad you didn't check back sooner. :[
    – lsuarez
    Commented Aug 31, 2011 at 21:09
  • For some reason the event is fired more than once on each enter/exit change for me. Commented Nov 17, 2016 at 12:24
  • @GerardReches Are you certain the event is fired twice, or is it possible you've attached your handler multiple times?
    – lsuarez
    Commented Nov 17, 2016 at 19:17
  • @lthibodeaux I'm sure, I attached the handler inside a function, and this function is only called once. At map load the event is fired once, when I enter to street view is fired two times, and when I exit street view is fired once. I don't know why is fired two times only when I enter to Street View. Commented Nov 18, 2016 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.