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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With