就像标题所说的那样,控制台告诉我我有一个缺失的API密钥,尽管我有一个权利,谷歌文档会说它。
的index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>My Google Map</title>
<style>
#map{
height:400px;
width:100%;
}
</style>
</head>
<body>
<h1>My Google Map</h1>
<div id="map"></div>
<script>
function initMap(){
var options = {
zoom: 8,
center: {lat:42.3601, lng:-71.0589}
}
var map = new google.maps.Map(document.getElementById('map'), options);
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?
key=Key_is_here&callback=initMap">
</script>
</body>
</html>
答案 0 :(得分:1)
所有Google Maps JavaScript API应用程序都需要身份验证。
<script async defer
src="https://maps.googleapis.com/maps/api/js?
key=Key_is_here&callback=initMap">
</script>
替换src脚本标记:<script src="https://maps.googleapis.com/maps/api/js?libraries=places&key=Past YOUR API KEY"></script>
答案 1 :(得分:0)
API包含网址中有空格。这是不正确的(API中的空格包含在“?”之后):
<script async defer
src="https://maps.googleapis.com/maps/api/js?
key=Key_is_here&callback=initMap">
</script>
这对我有用:
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=Key_is_here&callback=initMap">
</script>