Search code examples
pythongoogle-maps-api-3geocodezipcode

Find the location coordinates using zipcode in google geolocation api using python library googlemaps


I am using below code to find the location coordinates by taking zipcode from the user and want to suggest nearby stores to that zipcode.

It is giving the following error:

"REQUEST_DENIED
    The provided API key is invalid."

I am running the python code as below, tried searching on different websites still no success.

zipcode = 411018
api_key = "here i will input my api key"
url = "https://maps.googleapis.com/maps/api/geocode/xml?address="+str(zipcode)+"&key="+api_key
res = requests.get(url)
print(res.text)

zipcode 411018 should result in output as '18.635431,73.812498' but instead, it's throwing an error as shown above.


Solution

  • I don't know what your key string looks like, but maybe it requires URI encoding as it contains reserved characters? I.e. you can't simply append to the URL as-is.