检测谷歌地图街景模式 [英] Detecting Google Maps streetview mode

查看:127
本文介绍了检测谷歌地图街景模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何知道谷歌地图何时处于街景模式或路标模式?有没有事件被解雇?我试着翻看文档,似乎没有任何东西。我错过了什么?



当用户切换到街景模式时,我希望界面改变,但我不知道要绑定哪个事件。

解决方案

检测 StreetViewPanorama上的 visible_changed 事件与您的 Map 对象关联。您可以通过调用它的 getStreetView()方法从地图获取全景图,并将处理程序绑定到该对象的事件。您必须通过调用 getVisible()方法来测试 StreetViewPanorama 的可见性。



例如:

  var map = new google.maps.Map(document.getElementById theMap),{streetViewControl:true}); 

var thePanorama = map.getStreetView();

google.maps.event.addListener(thePanorama,'visible_changed',function(){

if(thePanorama.getVisible()){

//显示您的街景视图UI

}其他{

//显示您的原始UI

}

});

查看

How do I know when the google map is in streetview mode or roadmap mode? Is there an event that gets fired? I tried looking through the docs, and there doesn't seem to be anything. Am I missing something?

When the user switches into streetview mode, I want the UI to change, but I don't know which event to bind to.

解决方案

Detect the visible_changed event on the StreetViewPanorama associated with your Map object. You can get the panorama from the map by calling its getStreetView() method and bind the handler to that object's event. You will have to test the StreetViewPanorama's visibility by calling its getVisible() method.

For instance:

var map = new google.maps.Map(document.getElementById("theMap"), {streetViewControl: true});

var thePanorama = map.getStreetView();

google.maps.event.addListener(thePanorama, 'visible_changed', function() {

    if (thePanorama.getVisible()) {

        // Display your street view visible UI

    } else {

        // Display your original UI

    }

});

See the events section of the StreetViewPanorama Object Documentation for more events you can listen for on this object.

这篇关于检测谷歌地图街景模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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