当我点击一个地址时,我一直试图在地图上显示一个标记,但地图没有显示。
<div class="gmap_canvas">
<div id="g-map"></div>
</div>
<script src="https://maps.googleapis.com/maps/api/js?key=app_key&callback=initialize" async defer></script>
function initialize() {
var latlog = new google.maps.LatLng(39.305, -76.617);
var map = new google.maps.Map(
document.getElementById('g-map'), {
zoom: 4,
center: latlog
}
);
// The marker, positioned at map
var marker = new google.maps.Marker({
position: latlog,
map: map
});
}
您应该将style="width:100%; height:100%;
添加到gmap_canvasdiv中。
<body>
<div style="height:100%; width: 100%;">
<div id="map-canvas"></div>
</div>
</body>