Python3 reverse geocoding with google maps

Python October 27, 2018 python

When you run this code, it will fetch the geocoding results for the provided address and print the JSON representation of those results with proper indentation, making it easy to read. Remember to replace 'my_google_api_key' with your actual Google Geocoding API key for it to work properly.

python
import json
from pygeocoder import Geocoder

business_geocoder = Geocoder(api_key='my_google_api_key')
results = business_geocoder.geocode("address")

# Get a dictionary representation of the geocoding results
json_result = results.serialize()

# Convert the dictionary to a JSON string with indentation
json_string = json.dumps(json_result, indent=4)

# Print the JSON string
print(json_string)