简体   繁体   English

第二次加载时Google Maps无法加载

[英]Google Maps not loading when it is loaded second time

I called google map into a bootstrap panel. 我称Google Map为引导面板。 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 我使用了以下文件1.Bootstrap JS 2.Bootstrap css和3.Jquery JS和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 您可以在下面给出的我的网站上检查问题,以进行更多分析nirvanamrutam.com

Google maps API has nothing to do with reloading for the second time. Google Maps API与第二次重新加载无关。 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 查看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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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