简体   繁体   中英

Google Maps not loading when it is loaded second time

I called google map into a bootstrap panel. The map loads fine first time and in the second time it does not load. I tried resizing the map and many other solutions but it did not work.

I used the following files 1.Bootstrap JS 2.Bootstrap css and 3.Jquery JS and UI

The following is the code

 var NirMap = document.getElementById('placeMap'); if (GBrowserIsCompatible()) { var map = new GMap2(NirMap); map.setCenter(new GLatLng(_lat, _long), 17); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); } var mapOptions = { center: new google.maps.LatLng( _lat, _long), zoom: 17, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(NirMap, mapOptions); google.maps.event.addDomListener(window, 'load', initialize); 

You can check the problem at my site given below for more analysis nirvanamrutam.com

Google maps API has nothing to do with reloading for the second time. I've made a quick snippet which demonstrates the functionality, which clicked the "Zoom" button reloads the maps with random zoom. However, for every reload you need to make a new map object. View demo in JS Bin

 <!DOCTYPE html> <html> <head> <title>Simple Map</title> <meta name="viewport" content="initial-scale=1.0"> <meta charset="utf-8"> <style> html, body { height: 100%; margin: 0; padding: 0; } #map { height: 100%; } button { top: 10px; right: 10px; position: fixed; z-index: 999999; } </style> </head> <body> <div id="map"></div> <button onclick="initMap()">Zoom</button> <script> var map; function initMap() { map = new google.maps.Map(document.getElementById('map'), { center: { lat: -34.397, lng: 150.644 }, zoom: Math.floor(Math.random(10) * 10) }); } </script> <script src="https://maps.googleapis.com/maps/api/js?key=&callback=initMap" async defer></script> </body> </html> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM