如何检测在Google Maps API v3中输入和退出streetView [英] How to detect enter and exit streetView in Google Maps API v3

查看:100
本文介绍了如何检测在Google Maps API v3中输入和退出streetView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以检测用户在API v3下在Google Maps中进入和退出StreetView?

我想在触发现有的隐藏菜单功能时用户输入街景视图(因为菜单不相关),然后在退出菜单时重新显示菜单。 观察观察streetView的 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>


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 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>

这篇关于如何检测在Google Maps API v3中输入和退出streetView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆