twitter-bootstrap 如何使用 JavaScript 手动重新加载 Google 地图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17264989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 17:24:49  来源:igfitidea点击:

How to manually reload Google Map with JavaScript

javascriptgoogle-mapstwitter-bootstrap

提问by jvandemo

I am using this piece of code within a Bootstrap template. I am facing issues when loading images within a Bootstrap Tab content pane.

我在 Bootstrap 模板中使用这段代码。在 Bootstrap Tab 内容窗格中加载图像时遇到问题。

This is the JavaScript code which I use to initialize the Map:

这是我用来初始化 Map 的 JavaScript 代码:

var latlng = new google.maps.LatLng(50, 50);

var myOptions = {
    zoom: _zoom,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    mapTypeControlOptions: {
        style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
    }
};

var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);

var marker = new google.maps.Marker({
    position: latlng,
    map: map,
    title: 'Google Office!'
});

I have not found any method(s) on the internet to manually reload a Google Map instance.

我还没有在互联网上找到任何手动重新加载 Google 地图实例的方法。

Is this possible and how? Thanks!

这是可能的吗?谢谢!

回答by jvandemo

Yes, you can 'refresh' a Google Map like this:

是的,您可以像这样“刷新”谷歌地图:

google.maps.event.trigger(map, 'resize');

This basically sends a signal to your map to redraw it.

这基本上会向您的地图发送信号以重新绘制它。

Hope that helps!

希望有帮助!

回答by Daniel Loureiro

You can refresh with this:

你可以用这个刷新:

map.panBy(0, 0);

回答by Walty Yeung

map.setZoom(map.getZoom());

For some reasons, resizetrigger did not work for me, and this one worked.

由于某些原因,resize触发器对我不起作用,而这个起作用了。