Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.(5)

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/How to fix “geocode was not successful for the following reason: request_denied”
Next
Answered
Liam Mounier
  • 5
Liam Mounier
Asked: May 12, 20222022-05-12T07:37:11+00:00 2022-05-12T07:37:11+00:00In: Programs

How to fix “geocode was not successful for the following reason: request_denied”

  • 5

. 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.

request_denied
  • 2 2 Answers
  • 167 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    lyytutoria Expert
    2022-05-29T15:19:35+00:00Added an answer on May 29, 2022 at 3:19 pm

    The cause: it was async loading of the scripts.

    Solution: Try that jsfiddle on 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>
    Run code snippet
    • 21
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Adam Antoine
    2022-05-25T19:32:01+00:00Added an answer on May 25, 2022 at 7:32 pm

    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

    • 17
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.