如何使用JavaScript手动重新加载Google Map [英] How to manually reload Google Map with JavaScript
本文介绍了如何使用JavaScript手动重新加载Google Map的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Bootstrap模板中使用这段代码。在Bootstrap标签内容窗格中加载图片时遇到问题。
这是我用来初始化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!'
});
我没有在互联网上找到任何方法来手动重新加载Google Map实例。 / p>
这可能吗?谢谢!
解决方案
是的,您可以像这样'刷新'Google Map
google.maps.event.trigger(map,'resize');
这基本上会向您的地图发送信号来重绘它。
希望有所帮助!
I am using this piece of code within a Bootstrap template. I am facing issues when loading images within a Bootstrap Tab content pane.
This is the JavaScript code which I use to initialize the Map:
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.
Is this possible and how? Thanks!
解决方案
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!
这篇关于如何使用JavaScript手动重新加载Google Map的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文