谷歌地图显示错误 - https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error

时间:2016-08-27 09:27:15

标签: javascript google-maps google-maps-api-3

我想在谷歌地图中添加我的自定义图像,但页面未加载,提供错误说明MissingKeyMapError。我想我必须添加身份验证密钥,但我无法添加身份验证密钥

https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error

<!DOCTYPE html>
<html>
<head>
    <script src="https://maps.googleapis.com/maps/api/js?key=xyzKey" type="text/javascript"></script>


    <script>

var myCenter = new google.maps.LatLng(22.8046, 86.2029);
function initialize()
{
var mapProp = {
  center:myCenter,
  zoom:14,
  mapTypeId:google.maps.MapTypeId.ROADMAP
  };

var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);

var marker=new google.maps.Marker({
  position:myCenter,
  icon:'dustbin3.png'
});


marker.setMap(map);
}

google.maps.event.addDomListener(window, 'load', initialize);
    </script>
</head>

<body>
    <div id="googleMap" style="width:1500px;height:880px;"></div>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

在脚本网址

中添加api密钥
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY" type="text/javascript"></script>

参考https://developers.google.com/maps/documentation/javascript/get-api-key