时间:2010-07-23 21:09:19

标签: javascript google-maps mapping google-maps-api-3 google-street-view

1 个答案:

答案 0 :(得分:0)

我发现了同样令人讨厌的错误,并开发了一个带有更多div和一点CSS的解决方法。将streetView分配给#street

<div id="map" style="width:500px;height:300px;display:block"></div>
<div id="street" style="width:500px;height:300px;display:none"></div>

添加一个函数来切换div的可见性:

function toggleStreetView() {
  var mapDiv    = document.getElementById('map');
  var streetDiv = document.getElementById('street');

  var streetVisible = (streetDiv.style.display == 'block');
  if (streetVisible) {
    // hide streetView, show map
    streetDiv.display = 'none';
    mapDiv.display    = 'block';
  } else {
    // vice versa
    mapDiv.display    = 'none';
    streetDiv.display = 'block';
    streetView.setVisible(true); /* order important, show after div is visible */
  }      
}

也许不是最优雅的解决方案 - 但它确实有效。使用CSS绝对定位和JavaScript框架,我更喜欢jQuery,你可以添加一个很好的淡入淡出效果。