I have 3 websites with this google maps code which is working fine:
<script src="https://maps.googleapis.com/maps/api/js"></script>
<script>
function initialize() {
var myLatlng = new google.maps.LatLng(38.7223956, -9.1358012);
var mapOptions = {
zoom: 16,
center: myLatlng
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Something'
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<style>
h1 { background:none; padding:0; }
#map-canvas {
width:100%;
height:250px;
}
</style>
<div id="map-canvas"></div>
It's working great also if I'm just putting it on an html file on my hard drive. Recently, I started a Wordpress project on my localhost and I don't know why but when I'm adding this code to my project I get this:
Obviously I have already wordpress websites that working with the same exact code, I have no idea why suddenly I'm getting this message, It's unbelievable
答案 0 :(得分:3)
Judging by your link it looks like you're not setting an API key. If you are using the Google Maps API on a domain that was not active prior to June 22nd, 2016, it will require a key going forward.
See this link for an answer: https://www.latecnosfera.com/2016/06/google-maps-api-error-missing-keymap-error-solved.html
答案 1 :(得分:0)
The Google Maps Javascript API requires an API key.
Enforcement began some time in June I believe, but sites with a decent amount of traffic which were already using the API without a key got grandfathered in and don't have to comply (yet). That's why your other sites still work but new ones do not.