How to manually reload Google Map with JavaScript

JavascriptGoogle MapsTwitter Bootstrap

Javascript Problem Overview


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!

Javascript Solutions


Solution 1 - Javascript

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!

Solution 2 - Javascript

You can refresh with this:

map.panBy(0, 0);

Solution 3 - Javascript

map.setZoom(map.getZoom());

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1386320View Question on Stackoverflow
Solution 1 - JavascriptjvandemoView Answer on Stackoverflow
Solution 2 - JavascriptDaniel LoureiroView Answer on Stackoverflow
Solution 3 - JavascriptWalty YeungView Answer on Stackoverflow