【发布时间】:2015-05-01 07:38:39
【问题描述】:
有没有办法在 API v3 下检测用户何时在 Google 地图中进入和退出街景?
我想在用户进入街景时触发现有的“隐藏菜单”功能(因为菜单不相关),然后在用户退出时重新显示菜单。
【问题讨论】:
标签: google-maps google-maps-api-3 google-street-view
有没有办法在 API v3 下检测用户何时在 Google 地图中进入和退出街景?
我想在用户进入街景时触发现有的“隐藏菜单”功能(因为菜单不相关),然后在用户退出时重新显示菜单。
【问题讨论】:
标签: google-maps google-maps-api-3 google-street-view
您必须使用 visible_changed 事件侦听器并添加一个 doAlert() 函数。这将使街景能够在进入街景时发出警报,并在退出街景时发出警报。
【讨论】:
观察街景的visible_changed-事件,visible-属性将是true或false(打开或关闭)
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>
【讨论】: