javascript – (Google Map API) Geocode was not successful for the following reason: REQUEST_DENIED

javascript – (Google Map API) Geocode was not successful for the following reason: REQUEST_DENIED

Did you enable the Billing for API Key? Google Maps is no longer free. You have to associate a credit card so that you can get billed if your site has requests that exceed the $200 credit they give you monthly for free.

First of all, the problem was loading the scripts as async, remove it..

try that jsfiddle with your API KEY

(function(){
	let mapElement = map;
	let address = SPAIN;
	geocoder = new google.maps.Geocoder();
   geocoder.geocode({ address: address }, function (results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      var mapOptions = {
          zoom: 17,
          center: results[0].geometry.location,
          disableDefaultUI: true
      };
      var map = new google.maps.Map(document.getElementById(mapElement), mapOptions);
      var marker = new google.maps.Marker({
          map: map,
          position: results[0].geometry.location
      });
    } else {
    	alert(Geocode was not successful for the following reason:  + status);
    }
  });
})();
#map {
  width: 100%;
  height: 350px;
}
<script src=https://maps.googleapis.com/maps/api/js?key=APIKEY type=text/javascript></script>

<div id=map></div>

javascript – (Google Map API) Geocode was not successful for the following reason: REQUEST_DENIED

Nead to enable geocoding api that convert address to coordinates and it is a bit pricier, use coordinates instead of address and no need for Geocoding API

Leave a Reply

Your email address will not be published.