我正在构建一个占用 Google Maps JS API 的网站,但由于某种原因,地图保持白色,但Google Chrome Console 中没有错误。
<div id="map-container-5" class="z-depth-1" style="height: 200px"></div>
<script src="https://maps.google.com/maps/api/js?key"></script>
function myMap() {
var mapProp= {
center:new google.maps.LatLng(51.508742,-0.120850),
zoom:5,
};
var map=new google.maps.Map(document.getElementById("map-container- 5"),mapProp);
}
我不是很明白,为什么这不起作用,因为没有错误。
我的模板是:https : //www.w3schools.com/graphics/tryit.asp?filename=trymap_intro
如果您只想使用 googleapi 显示带有坐标的地图,请执行以下操作。这将显示带有您的 lat 和 lng 的地图。
CSS:
#map {
height: 400px; /* The height is 400 pixels */
width: 100%; /* The width is the width of the web page */
}
HTML
<div id="map"></div> /* Place on your page
这是在 /body 标签与您的密钥之前
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOURKEY&callback=initMap">
</script>
而 JS 脚本又是关于 /body 的地方
<script>
function initMap() {
// The location of Uluru
var uluru = {lat: 51.5087420, lng: -0.120850};
// The map, centered at Uluru
var map = new google.maps.Map(
document.getElementById('map'), {zoom: 10, center: uluru});
// The marker, positioned at Uluru
var marker = new google.maps.Marker({position: uluru, map: map});
}
</script>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句