Nimrodshn
Nimrodshn

Reputation: 971

Working with Google Maps API in Python

I've been trying to work with the google maps api and i keep getting this error:

"HTTPError: HTTP Error 403:Forbidden."

take for example this simple case (its based on a more elaborate case where i extract the adress from an XML):

from googlemaps import GoogleMaps
import xml.etree.ElementTree as et
gmaps = GoogleMaps()
pars = et.XMLParser(encoding='utf-8')
tree = et.parse('data.xml',parser=pars)
root = tree.getroot()
adress = "ringelblum 7 beer sheva"
lat , lng = gmaps.address_to_latlng(adress)
print lat, lng 

i've seen different videos and tutorials and it should be very simple. why doesnt it work? Thanks a lot guys.

Upvotes: 2

Views: 6577

Answers (1)

DeepSpace
DeepSpace

Reputation: 81594

You could try this, you will need to have a key from google, the requests library and know your way with json:

geo_s ='https://maps.googleapis.com/maps/api/geocode/json'

param = {'address': address, 'key': 'YOUR_KEY'}

response = requests.get(geo_s, params=param)

json_dict = response.json()

lat = json_dict['results'][0]['geometry']['location']['lat']
lng = json_dict['results'][0]['geometry']['location']['lng']

print({'lat': lat, 'lng': lng})

Upvotes: 4

Related Questions