Skip to content

Instantly share code, notes, and snippets.

@barredterra
Last active May 27, 2025 14:50
Show Gist options
  • Save barredterra/dbc9aa998b8f3a8bf5a818ab7ca024d2 to your computer and use it in GitHub Desktop.
Save barredterra/dbc9aa998b8f3a8bf5a818ab7ca024d2 to your computer and use it in GitHub Desktop.
Get distance between two places via Google Routes API
# 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