Call Google Maps Geocoding Api in Google Cloud Functions (Python)

Enable Google Maps Platform

Get API Keys

NOTE: Make sure Geocoding API is enabled.

requirements.txt

# https://pypi.org/project/googlemaps/
googlemaps==3.0.2

main.py

def test_geocoding(request):    import googlemaps    from flask import jsonify    # 40.714224, -73.961452    location = request.json.get('location')    if location:        location = tuple(location.split(', '))    if not location:        abort(422)    API_KEY = 'AIza ...'    gmaps = googlemaps.Client(key=API_KEY)    result = gmaps.reverse_geocode(location)    return jsonify(result)

Test

curl -X POST [URL]/test_geocoding -H "Content-Type:application/json" -d '{"location":"40.714224, -73.961452"}'

References:

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.