Bhavesh Chauhan
Bhavesh Chauhan

Reputation: 1053

Google Map Api - google map not showing properly after load second time

I am opening google map in bootstrap modal. When I click on link to open google map modal, it is showing well, after close modal if I am open google map modal second time map is not showing as open first time check images to understand problemfirst time open google map modal

second time open google map modal without refresh page

please check first image,in that pullen park(one park is showing on map) is showing bottom right corner but when I open google map modal again pullen park is showing top left corner,so why pullen park is not showing same as first image.

Upvotes: 2

Views: 2627

Answers (2)

user4692688
user4692688

Reputation:

simply just put

google.maps.event.addListener(map, 'resize', function() {
    map.setCenter(marker.getPosition());
});

Upvotes: 1

kaho
kaho

Reputation: 4784

It is probably due to some hiding issues. You might want to recenter your map after you do google.maps.event.trigger(map, 'resize');, or listen to the resize event like the following:

google.maps.event.addListener(map, 'resize', function() {
    console.log("resize triggered");
});

for more about resize: https://developers.google.com/maps/documentation/javascript/reference

for more about event: https://developers.google.com/maps/documentation/javascript/events

Upvotes: 1

Related Questions