【问题标题】:goMap jquery plugin redraw mapgoMap jquery插件重绘地图
【发布时间】:2012-06-27 12:06:55
【问题描述】:

我正在使用goMap jQuery 插件来集成 Google Maps api v3。我想重绘地图时遇到问题。我有 2 个用于输入纬度和经度的输入框,然后是一个文本链接,我在该链接上触发 goMap javascript 代码......当第一次调用地图时,地图呈现正常,但是如果我更改纬度/经度值并再次调用相同的代码地图没有重绘到新坐标...我的代码看起来像

<input id="form_office_latitude" class="span4 office_latitude" type="text"  name="office_latitude" value="">
<input id="form_office_longitude" class="span4 office_longitude" type="text" name="office_longitude" value="">
<a class="check-map" href="javascript:{};">Preveri zemljevid</a>

$('.check-map').live('click', function(){
        $("#map_canvas").goMap({ 
            maptype: 'ROADMAP',
            zoom: 15,
            markers: [{
                icon: base_url+'assets/img/marker.png',
                latitude: $('.office_latitude').val(), 
                longitude: $('.office_longitude').val(), 
                id: 'test', 
                html: { 
                    content: 'Hello Word!', 
                    popup: true 
                }
            }], 
            hideByClick: false 
        });
});

【问题讨论】:

    标签: jquery jquery-plugins google-maps-api-3


    【解决方案1】:

    我不是 goMap 插件方面的专家,但您可能不想像现在这样重绘或重新创建地图(构建一个全新的地图)。相反,您想使用以下方式重新定位地图:

    var center = new google.maps.LatLng($('.office_latitude').val(),
                                        $('.office_longitude').val());
    $.goMap.map.setCenter(center);
    

    【讨论】:

    • 调用 $.goMap.map.setCenter(center); 还有另一个问题。如果您在一页中有多个地图实例(就像我一样),那么调用 $.goMap.map.setCenter(center) 不会将我想要的地图居中...
    • 更新:没关系我想通了。 goMap 知道它是否已经渲染。你的回答是对的!更好的是调用$.goMap.map.createMarker(markerOptions);,它将根据markerOptions创建标记并将地图居中。
    猜你喜欢
    • 1970-01-01
    • 2013-04-11
    • 2012-12-15
    • 1970-01-01
    • 2023-03-10
    • 2013-12-14
    • 2013-02-17
    • 1970-01-01
    • 2011-07-09
    相关资源
    最近更新 更多