开发者

Toggle Street View

How can I toggle Streetview on an specific map canvas by clicking a button (API v3) ?

function ToggleStreetView(map)
{
 开发者_如何学Python //Assume map contains the google.maps.Map object

}


This is the function that I wrote for a maps app that I wrote a while ago:

// Toggles between map and panorama view
function togglePanorama(){
    if(isPanorama){
        map.streetView.setVisible(false);
        $('#message').empty().append('Click here to take a tour of our office.');
        isPanorama = 0;
    } else{
        map.streetView.setVisible(true);
        $('#message').empty().append('Back to the map.');
        isPanorama = 1;
    }
}

Though I was using it with a custom panorama it will work just fine with the default Street View.


Get the 'streetview' of your map then setVisible to 'false' and your streetview should no longer be visible.

// map would be map instance
map.getStreetView().setVisible(false);


I assume you are using Javascript version 3 API from google maps here is a sample code

<script type="text/javascript">
  function initialize() {
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
      zoom: 8,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
  }

</script>

if you lool carefully you can see line of code

mapTypeId: google.maps.MapTypeId.ROADMAP

you can declare our map variable and than iinside your function change its MapTypeId

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜