首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >切换google地图中的信息框

切换google地图中的信息框
EN

Stack Overflow用户
提问于 2012-08-14 06:10:35
回答 2查看 3.2K关注 0票数 0

我正在谷歌地图中工作,并成功地实现了谷歌地图的信息框插件,我担心的是,我们如何知道标记的信息框是否处于开放状态?所以我可以按一下记号键.

代码语言:javascript
运行
复制
var locations = [
        //this is array of arrays
    ];

    var map = new google.maps.Map(document.getElementById('map_canvas'),{
        disableDefaultUI : true,
        zoom : 12,
        center : new google.maps.LatLng(defaultLatitude,defaultLongitude),
        mapTypeId : google.maps.MapTypeId.ROADMAP
    });


    var mapcode,myOptions;

    for (var i = 0,len = locations.length; i < len; i++) {
        var marker = add_marker(locations[i][1],locations[i][2],locations[i][3],'this is title',locations[i][0]);
        allMarkers.push(marker);
        marker.setMap(map);
    };

    function add_marker(lat,lng,icn,title,box_html) {

        var marker = new google.maps.Marker({
            animation : google.maps.Animation.DROP,
            position : new google.maps.LatLng(lat,lng),
            map : map,
            icon : icn
        }); 

        mapcode = '<this is the code of infobox to show>';

        myOptions = {
             //options of the infobox...bla bla
        };

        var ib = new InfoBox(myOptions);

        google.maps.event.addListener(marker, 'click', function() {
            ib.open(map, marker);
        });   
        return marker;
    }

我是新在谷歌地图所以可能是我错过了一些非常小的stuff...thanks在预先.安库尔

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-08-14 09:40:49

如果您只需要随时打开一个信息框,您就可以这样做:

代码语言:javascript
运行
复制
    var ib = new InfoBox();
    ib.isOpen = false;
    function add_marker(lat,lng,icn,title,box_html) {

    var marker = new google.maps.Marker({
        animation : google.maps.Animation.DROP,
        position : new google.maps.LatLng(lat,lng),
        map : map,
        icon : icn
    }); 

    mapcode = '<this is the code of infobox to show>';

    myOptions = {
         //options of the infobox...bla bla
    };
    marker.ibOptions = myOptions;

    google.maps.event.addListener(marker, 'click', function() {
        ib.setOptions(marker.ibOptions);
        ib.open(map, marker);
        ib.isOpen = true;
    });   
    return marker;
}

如果您这样做,则每次使用ib.close=false调用ib.isOpen ()时都需要重置标志(您没有指定在什么情况下关闭该框)

如果您需要打开多个框:

代码语言:javascript
运行
复制
function add_marker(lat,lng,icn,title,box_html) {

    var marker = new google.maps.Marker({
        animation : google.maps.Animation.DROP,
        position : new google.maps.LatLng(lat,lng),
        map : map,
        icon : icn
    }); 

    mapcode = '<this is the code of infobox to show>';

    myOptions = {
         //options of the infobox...bla bla
    };

    var ib = new InfoBox(myOptions);
    ib.isOpen = false;
    marker.ib = ib;

    google.maps.event.addListener(marker, 'click', function() {
        marker.ib.open(map, marker);
        marker.ib.isOpen = true;
    });   
    return marker;
}

同样,如果调用allMarkers....ib.close(),则需要使用allMarkers....ib.isOpen =false重置标志;

我希望这能帮到你。

票数 2
EN

Stack Overflow用户

发布于 2012-10-03 11:34:19

您可以在Google地图的单击事件侦听器中检查是否已经打开了infowindow。你可以这样检查:

代码语言:javascript
运行
复制
var ib = new InfoBox(myOptions);
google.maps.event.addListener(marker, 'click', function() {
    if(ib)
        ib.close();
    marker.ib.open(map, marker);
}

我希望这能解决你的问题。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11946679

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档