user3744279
user3744279

Reputation: 21

Why does Geocoder (1.38.1) output None?

Why does the below piece of code give None as the output?

import geocoder
g = geocoder.google('Mountain View, CA')
print g.latlng

Upvotes: 2

Views: 1152

Answers (1)

Mihai Chelaru
Mihai Chelaru

Reputation: 8232

To find the answer you can use the other code they provide for manually doing what geocoder does:

import requests
url = 'https://maps.googleapis.com/maps/api/geocode/json'
params = {'sensor': 'false', 'address': 'Mountain View, CA'}
r = requests.get(url, params=params)
results = r.json()

Looking in this object we can see that it contains an error_message key, as well as the status OVER_QUERY_LIMIT. The error message reads as follows:

print(results['error_message'])

You have exceeded your rate-limit for this API. We recommend registering for a key at the Google Developers Console: https://console.developers.google.com/apis/credentials?project=_

This is due to the fact that Google stopped supporting keyless API access back on June 11, 2018. To use Google as the provider for geocoding you'll need to get an API key and enable billing. You may want to look at some free alternatives for geocoding out there if you don't want to pay for their API access.

EDIT: Looks like the geocoder documentation also has a list of alternatives that you can try using.

Upvotes: 2

Related Questions