Calculate a Distance

Use the followith URL template to calculate distance and time. Request type must be POST for both XML and JSON format.

http://trackservice.trackroad.com/rest/distance/key

You must login to get a key.

For more details about request see DistanceSpecification and DistanceResult.

ABSTRACT SAMPLE

XML

To receive response in XML format you must specify content type text/xml or application/xml. For example:

...
httpWReq.Method = "POST";
httpWReq.ContentType = "text/xml; charset=utf-8";
httpWReq.ContentLength = data.Length;
...

XML request

The following request uses two addresses.

<DistanceSpecification>
  <StartLocation>
    <Address>
      <Street>6718 Whittier Avenue</Street>
      <City>McLean</City>
      <State>VA</State>
      <PostalCode>22101</PostalCode>
    </Address>
  </StartLocation>
  <FinishLocation>
    <Address>
      <Street>1450 Old Chaing Bridge Road</Street>
    </Address>
  </FinishLocation>
  <DistanceUnit>Mile</DistanceUnit>
</DistanceSpecification>

XML response

<DistanceResult xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Errors />
  <Status>Success</Status>
  <StartLocationMatchCode>Good</StartLocationMatchCode>
  <FinishLocationMatchCode>Good</FinishLocationMatchCode>
  <Distance>0.63162381690925</Distance>
  <Time>112</Time>
</DistanceResult>

XML request

The following request uses two locations with Latitude/Longitude.

<DistanceSpecification>
  <StartLocation>
    <LatLong>
      <Latitude>-23.554533</Latitude>
      <Longitude>-46.6922909</Longitude>
    </LatLong>
  </StartLocation>
  <FinishLocation>
    <LatLong>
      <Latitude>-23.654533</Latitude>
      <Longitude>-46.49229</Longitude>
    </LatLong>
  </FinishLocation>
  <DistanceUnit>Mile</DistanceUnit>
</DistanceSpecification>

XML response

<DistanceResult xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Errors />
  <Status>Success</Status>
  <StartLocationMatchCode>None</StartLocationMatchCode>
  <FinishLocationMatchCode>None</FinishLocationMatchCode>
  <Distance>20.851912331981225</Distance>
  <Time>1976</Time>
</DistanceResult>

JSON

To receive response in JSON format you must specify content type text/json or application/json. For example:

...
httpWReq.Method = "POST";
httpWReq.ContentType = "text/json; charset=utf-8";
httpWReq.ContentLength = data.Length;
...

JSON request

The following request uses two addresses.

{
   "StartLocation":{
      "MatchCode":0,
      "Name":"Stop A",
      "Delivery":null,
      "Vehicle":null,
      "Description":null,
      "Phone":null,
      "LatLong":null,
      "Address":{
         "Street":"6718 Whittier Avenue",
         "City":"McLean",
         "State":"VA",
         "PostalCode":"22101",
         "Country":null
      },
      "Priority":0,
      "Wait":0,
      "Volume":0,
      "Weight":0,
      "Skids":0,
      "TimeConstraintArrival":"0001-01-01T00:00:00Z",
      "TimeConstraintDeparture":"0001-01-01T00:00:00Z",
      "TimeConstraintArrival2":"0001-01-01T00:00:00Z",
      "TimeConstraintDeparture2":"0001-01-01T00:00:00Z",
      "LocationType":0,
      "CanArriveEarly":true,
      "Distance":0,
      "Time":0
   },
   "FinishLocation":{
      "MatchCode":0,
      "Name":"Stop B",
      "Delivery":null,
      "Vehicle":null,
      "Description":null,
      "Phone":null,
      "LatLong":null,
      "Address":{
         "Street":"1450 Old Chaing Bridge Road",
         "City":null,
         "State":null,
         "PostalCode":null,
         "Country":null
      },
      "Priority":0,
      "Wait":0,
      "Volume":0,
      "Weight":0,
      "Skids":0,
      "TimeConstraintArrival":"0001-01-01T00:00:00Z",
      "TimeConstraintDeparture":"0001-01-01T00:00:00Z",
      "TimeConstraintArrival2":"0001-01-01T00:00:00Z",
      "TimeConstraintDeparture2":"0001-01-01T00:00:00Z",
      "LocationType":0,
      "CanArriveEarly":true,
      "Distance":0,
      "Time":0
   },
   "DistanceUnit":0
}

JSON Response

{
   "StartLocationMatchCode":3,
   "FinishLocationMatchCode":3,
   "Distance":0.63162381690925,
   "Time":112,
   "Errors":[

   ],
   "Status":1
}

JSON request

The following request uses two locations with Latitude/Longitude.

{
   "StartLocation":{
      "MatchCode":0,
      "Name":"Stop B",
      "Delivery":null,
      "Vehicle":null,
      "Description":null,
      "Phone":null,
      "LatLong":{
         "Latitude":-23.554533,
         "Longitude":-46.6922909
      },
      "Address":null,
      "Priority":0,
      "Wait":0,
      "Volume":0,
      "Weight":0,
      "Skids":0,
      "TimeConstraintArrival":"0001-01-01T00:00:00Z",
      "TimeConstraintDeparture":"0001-01-01T00:00:00Z",
      "TimeConstraintArrival2":"0001-01-01T00:00:00Z",
      "TimeConstraintDeparture2":"0001-01-01T00:00:00Z",
      "LocationType":0,
      "CanArriveEarly":true,
      "Distance":0,
      "Time":0
   },
   "FinishLocation":{
      "MatchCode":0,
      "Name":null,
      "Delivery":null,
      "Vehicle":null,
      "Description":null,
      "Phone":null,
      "LatLong":{
         "Latitude":-23.654533,
         "Longitude":-46.49229
      },
      "Address":null,
      "Priority":0,
      "Wait":0,
      "Volume":0,
      "Weight":0,
      "Skids":0,
      "TimeConstraintArrival":"0001-01-01T00:00:00Z",
      "TimeConstraintDeparture":"0001-01-01T00:00:00Z",
      "TimeConstraintArrival2":"0001-01-01T00:00:00Z",
      "TimeConstraintDeparture2":"0001-01-01T00:00:00Z",
      "LocationType":0,
      "CanArriveEarly":true,
      "Distance":0,
      "Time":0
   },
   "DistanceUnit":0
}

JSON Response

{
   "StartLocationMatchCode":0,
   "FinishLocationMatchCode":0,
   "Distance":20.851912331981225,
   "Time":1976,
   "Errors":[

   ],
   "Status":1
}

See Also

DistanceSpecification
DistanceResult