Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot import name GoogleMaps in python

I am using the code below to get the latitude & longitude of an address:

from googlemaps import GoogleMaps
gmaps = GoogleMaps(api_key)
address = 'Constitution Ave NW & 10th St NW, Washington, DC'
lat, lng = gmaps.address_to_latlng(address)
print lat, lng

but am getting the error below

File "C:/Users/Pavan/PycharmProjects/MGCW/latlong6.py", line 1, in <module>
    from googlemaps import GoogleMaps
ImportError: cannot import name GoogleMaps

I have seen another question similar to this, but the solution didn't work for me.

like image 894
Pavan Chakravarthy Avatar asked May 29 '15 07:05

Pavan Chakravarthy


People also ask

Can you import Google Maps in Python?

GoogleMaps library is a python-based library that offers Web Services of Google Maps platform onto your Python application. You can access the Google Maps services like Places, Directions, Distance Matrix, etc. with APIs. GoogleMaps library is the cross-platformed library.


1 Answers

Use geopy instead, no need for api-key.

From their example:

from geopy.geocoders import Nominatim
geolocator = Nominatim()
location = geolocator.geocode("175 5th Avenue NYC")
print(location.address)
print((location.latitude, location.longitude))

prints:

Flatiron Building, 175, 5th Avenue, Flatiron, New York, NYC, New York, 10010,  United States of America
(40.7410861, -73.9896297241625)
like image 63
Scott Avatar answered Oct 14 '22 20:10

Scott