Use this template

Calculating driving distance between two addresses

Overview

This template computes the driving distance (in meters) between two addresses.

How the template works

Workflow JSON input

{
  "fromAddress": "<string, required>",
  "destinationAddress": "<string, required>"
}

Workflow example JSON input

{
  "fromAddress": "500 Oracle Parkway, Redwood City, CA",
  "destinationAddress": "1 Apple Park Way, Cupertino, CA"
} 

What it does

  1. Geocoding

    • Sends the fromAddress and destinationAddress to Nominatim to obtain latitude and longitude for each.

    • Example Nominatim request (HTTP GET):

      https://nominatim.openstreetmap.org/search?q=<URL-encoded address>&format=jsonv2&limit=1
      
    • The first result's lat and lon are used.

  2. Routing

    • Sends the coordinates to Open Source Routing Machine (OSRM) to get a driving route and distance (in meters).

    • Example OSRM request (HTTP GET):

      https://router.project-osrm.org/route/v1/driving/<lon_from>,<lat_from>;<lon_to>,<lat_to>?overview=false&alternatives=false&steps=false
      
  3. Response

    • Parses OSRM's response and returns the distance in meters (from the first route's distance field).

    • Workflow JSON output:

      {
        "from": "<string>",
        "distance": <number>,
        "destination": "<string>"
      }
      

How to use the template

  1. Click Use this template button on the top right of this page.

  2. Click Save button.

  3. Toggle the Enable checkbox to enable the workflow definition.

Relevant resources