【发布时间】:2017-07-07 17:05:57
【问题描述】:
我没有使用 google map API 的经验,所以希望你能帮助我。
问题是每当我点击显示按钮时,地图的宽度就会出现,但它没有加载,我根本看不到地图。
但如果我在开发者工具中打开顾问,地图会正常加载!
codepen url 以获得更好的解释 https://codepen.io/ahmadz12/pen/QdRQbE
html
<div id="map-canvas" class='hide'></div>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false" type="text/javascript"></script>
<a id='show'>show</a>
css
#map-canvas{
height: 500px;
width: 500px;
border: 3px solid black;
}
.hide{
display:none;
}
javascript
if (document.getElementById('map-canvas')){
// Coordinates to center the map
var myLatlng = new google.maps.LatLng(52.525595,13.393085);
// Other options for the map, pretty much selfexplanatory
var mapOptions = {
zoom: 14,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// Attach a map to the DOM Element, with the defined settings
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
}
$('#show').click(function(){
$('#map-canvas').removeClass( "hide" )
});
谢谢
【问题讨论】:
标签: javascript jquery api google-maps