Search code examples
jquerygoogle-mapsgoogle-maps-api-3google-street-view

Google Maps API button that changes road to street view


Currently I am outputting 2 google maps on the page, the first outputs the normal road map view, the second, street view.

Is there a way that I could load only one instance of a Google map but when clicking on a button, it'll toggle to street view?


Solution

  • Worked out it out by declaring a var panorama and set to setVisible on click of button:

    var panorama = map.getStreetView();
          panorama.setPosition(latlng);
          panorama.setPov({
              heading: 45,
              pitch:-10}
          );
        $("#myBtn").on('click', function(){
                panorama.setVisible(true);
        });