如何检测在Google Maps API v3中输入和退出streetView [英] How to detect enter and exit streetView in Google Maps API v3
问题描述
有没有一种方法可以检测用户在API v3下在Google Maps中进入和退出StreetView?
我想在触发现有的隐藏菜单功能时用户输入街景视图(因为菜单不相关),然后在退出菜单时重新显示菜单。 观察观察streetView的 Is there a way to detect when a user enters and exits StreetView in Google Maps under API v3? I want to trigger an existing 'Hide Menu' function when the user enters StreetView (as the menu isn't relevant) and then re-show the menu when they exit. Observe the
这篇关于如何检测在Google Maps API v3中输入和退出streetView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! visible_changed
-event, visible
-property将会是 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%;保证金:0;填充:0; }
< script src =https:// maps .googleapis.com / maps / api / js?v = 3& .js>< / script>< div id =map-canvas>< / div>
visible_changed
-event of the streetView, the visible
-property will be true
or false
(open or closed) 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>