Skip to content

Geocoding Distance

Request URL

POST /geo/distance

Schema

Property table for schema 1 for geo/distance

Property Description Required Schema
sources sources Yes {
  "type": "string"
}
destinations destinations Yes {
  "type": "string"
}
arriveBy arriveBy No {
  "type": "string",
  "nullable": true
}

Property table for schema 2 for geo/distance

Property Description Required Schema
sources sources Yes array of {
  "type": "string"
}
destinations destinations Yes array of {
  "type": "string"
}
arriveBy arriveBy No {
  "type": "string",
  "nullable": true
}

Request Body

{
  "sources": ["123 Main Str, Harrisburg, PA 12345"],
  "destinations": ["175 5th Ave, New York, NY 10010", "40.7403809 -73.9897337"],
  "arriveBy": "Wed Oct 27 2021 16:52:52 GMT-0400"
}

Snippet Examples

javascript

const axios = require('axios');
const data = {
  "sources": ["123 Main Str, Harrisburg, PA 12345"],
  "destinations": ["175 5th Ave, New York, NY 10010", "40.7403809 -73.9897337"],
  "arriveBy": "Wed Oct 27 2021 16:52:52 GMT-0400"
};
const config = {
  method: 'POST',
  url: '${AMPLIFI_BASE_URL}/geo/distance',
  headers: {
    'Content-Type': "application/json",
    'token': "A long random string token received from /token request"
  },
  data
};

let result;
try {
  result = await axios.request(config);
  if (result.status === 200) {
    console.log(JSON.stringify(result.data));
  }
} catch (err) {
  console.log({
    errCode: err.code,
    responseStatus: err.response && err.response.status,
    data: err.response && JSON.stringify(err.response.data)
  });
}

cURL

curl --location "AMPLIFI_BASE_URL/geo/distance" --data "{  \"sources\":[\"123 Main Str,Harrisburg,PA 12345\"], \"destinations\":[\"175 5th Ave,New York,NY 10010\",\"40.7403809 -73.9897337\"], \"arriveBy\":\"Wed Oct 27 2021 16:52:52 GMT-0400\"}" --header "Content-Type: application/json" --header "token: A long random string token received from /token request" 

Successful Response Examples

200 GEO/DISTANCE

HEADERS

Header Value
Content-Type application/json
token A long random string token received from /token request

REQUEST BODY

{
  "sources": ["123 Main Str, Harrisburg, PA 12345"],
  "destinations": ["175 5th Ave, New York, NY 10010", "40.7403809 -73.9897337"]
}

RESPONSE BODY

{
    "success": true,
    "matrix":  [  //an array of travel times from each of the sources and to each of the destinations.
      {
        "originalSource": "123 Main Str, Harrisburg, PA 12345",
        "originalDestination": "175 5th Ave, New York, NY 10010",
        "source": {}, //normalized address
        "destination": {}, //normalized address
        "distance": 100, //distance in km
        "duration": 125 //travel time in minutes
      }
    ]
}