当尝试运行代码时, map 没有显示,并显示此错误“Google Maps API 警告:NoApiKeys”
。有什么可能的解决方案?这是我添加的脚本:
<script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
这些是我放在 js 文件中的代码:
$(document).ready(function () {
var myOptions = {
zoom: 11,
center: new google.maps.LatLng(1.363083, 103.909836),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map_canvas'),
myOptions);
var myLatlng = new google.maps.LatLng(1.443107 , 103.795681);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: "Map "
})
});
该错误表明您没有在 Google map API 调用中包含 API key 。你需要去 https://developers.google.com/maps/ ,注册一个 API key ,并将其包含在您的调用中。下面是一个使用 JS api 的非常简单的示例。
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY></script>
我是一名优秀的程序员,十分优秀!