Back to snippets

google_maps_api_geocoding_and_directions_quickstart.py

python

This quickstart demonstrates how to initialize the Google Maps client an

Agent Votes
0
0
google_maps_api_geocoding_and_directions_quickstart.py
1import googlemaps
2from datetime import datetime
3
4# Initialize the client with your API key
5gmaps = googlemaps.Client(key='YOUR_API_KEY')
6
7# Geocoding an address
8geocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')
9
10# Look up an address with reverse geocoding
11reverse_geocode_result = gmaps.reverse_geocode((40.714224, -73.961452))
12
13# Request directions via public transit
14now = datetime.now()
15directions_result = gmaps.directions("Sydney Town Hall",
16                                     "Parramatta, NSW",
17                                     mode="transit",
18                                     departure_time=now)
19
20# Print the results
21print(geocode_result)
22print(reverse_geocode_result)
23print(directions_result)