使用google map api时我的控制台出错:-Uncaught ReferenceError:未定义initialize 有什么帮助吗?
JS
<script type="text/javascript">
function initialize() {
var myLatLng = {lat: 42.52501, lng: 2.938979};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: myLatLng,
scrollwheel: false,
draggable:true,
});
var image='logo.png';
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon:image
});
}
</script>
的header.php
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key='YOUR API KEY HERE'"></script>
<script src='https://maps.googleapis.com/maps/api/js?v=3.exp'></script>
<body onload="initialize()";></body>
答案 0 :(得分:2)
你打电话给谷歌地图api两次,身体没有代码,并且不清楚脚本在初始化函数的位置......
我玩了你的代码......
<强>的header.php 强>
<script src='https://maps.googleapis.com/maps/api/js?v=3.exp'></script>
<body>
<div id="map" style="height:500px; width:500px;"></div>
<script>
function initialize() {
var myLatLng = {lat: 42.52501, lng: 2.938979};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: myLatLng,
scrollwheel: false,
draggable:true,
});
var image='logo.png';
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon:image
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</body>