. Advertisement .
..3..
. Advertisement .
..4..
As the title says, I am getting the “geocode was not successful for the following reason: request_denied” error. How can I fix it so the error goes away? Here is my detail:
<script async defer src="https://maps.googleapis.com/maps/api/js?key=APIkey&callback=initMap"
type="text/javascript"></script>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=APIKEY&callback=mapAddress"
type="text/javascript"></script>
<!-- &callback=mapAddress -->
<script>
function mapAddress(mapElement, address) {
var geocoder = new google.maps.Geocoder();
// alert(mapElement);
// alert(address);
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);
}
});
}
</script>
<button type="button" class="button_mapAPI" id="address_<?php echo $case["id"]; ?>" value="<?= $case['location_detail'] ?>" onclick="mapAddress('map1', 'Hong Kong')"/>Map Refresh</button>
When I operated it and I received the error text:
Geocode was not successful for the following reason: REQUEST_DENIED
I appreciate any help from you.
The cause: it was async loading of the scripts.
Solution: Try that jsfiddle on your API KEY
Have you enabled the Billing for API Key feature? Google Maps is no more free. To be able to get billed for requests exceeding the $200 credit you receive each month, you will need to associate a credit account