我试图在我的网站上显示谷歌地图。这是代码: -
<script>
function initMap() {
var uluru = {lat: -25.363, lng: 131.044};
var map = new google.maps.Map(document.getElementById('mapz'), {
zoom: 4,
center: uluru
});
var marker = new google.maps.Marker({
position: uluru,
map: map
});
}
</script>
以下是控制台中显示的错误: - 消息:“initMap不是函数” 名: “InvalidValueError”
答案 0 :(得分:1)
尝试以下代码。希望它可以帮助你......!
<script type="text/javascript" src = "http://maps.google.com/maps/api/js?key=MYAPIKEY&sensor=false">
<div id="mapz" style="width: 80%; height: 500px"></div>
<script>
google.maps.event.addDomListener(window, 'load', initMap);
function initMap() {
var uluru = {lat: -25.363, lng: 131.044};
var map = new google.maps.Map(document.getElementById('mapz'), {
zoom: 4,
center: uluru
});
var marker = new google.maps.Marker({
position: uluru,
map: map
});
}
</script>