Last active
May 27, 2025 14:50
-
-
Save barredterra/dbc9aa998b8f3a8bf5a818ab7ca024d2 to your computer and use it in GitHub Desktop.
Get distance between two places via Google Routes API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TODO: | |
# 1. Enable API: https://console.cloud.google.com/marketplace/product/google/routes.googleapis.com | |
# 2. Create an API Key: https://console.cloud.google.com/google/maps-apis/credentials | |
resp = frappe.make_post_request( | |
url="https://routes.googleapis.com/distanceMatrix/v2:computeRouteMatrix", | |
headers={ | |
"Content-Type": "application/json", | |
"X-Goog-Api-Key": "YOUR_API_KEY_HERE", | |
"X-Goog-FieldMask": "distanceMeters" | |
}, | |
json={ | |
"origins": [ | |
{ | |
"waypoint": { | |
"address": "Leipzig, Germany" | |
} | |
} | |
], | |
"destinations": [ | |
{ | |
"waypoint": { | |
"address": "Paris, France" | |
} | |
} | |
] | |
} | |
) | |
distance_in_meters = resp[0]["distanceMeters"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment