【发布时间】:2015-11-09 11:44:54
【问题描述】:
这一次,我直接进入正题:
HTML:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="code.js"></script>
</head>
<body>
<div id="map"></div>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=*snip*&callback=initMap">
</script>
</body>
</html>
Code.js:
$(document).ready(function () {
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {
lat: -34.397,
lng: 150.644
},
zoom: 10
});
}
});
结果:
Uncaught TypeError: window.initMap is not a function.
提示?
另外,想知道这部分是否:
<script async defer src="https://maps.googleapis.com/maps/api/js?key=*snip*&callback=initMap">
可以移动到同一个 code.js 文件中。
【问题讨论】:
标签: javascript google-maps-api-3