Skip to main content

Updating the actual locations of resources

There are two types of addresses that can be used to display the resources' locations on the map:

  • Static addresses such as the depot address or the employee's home address
  • Dynamic addresses as provided by tracking devices, mobile phones, tablets, etc.

The former is static data that is passed along with the Resource entity, while the latter has its dedicated entity named ResourceGpsTracking. Any system that is able to make a HTTP POST request is eligible to interact with our API that will push the last known location to the map in Dime.Scheduler.

To update the current location of a resource in Dime.Scheduler, three properties need to be provided:

  • The Resource No
  • The latitude
  • The longitude

The location trackers will obviously provide the coordinates and an identifier of the tracker. To connect these trackers to Dime.Scheduler, you will need to manage a list that maps tracking devices to the resource numbers. Once that's covered, it's smooth sailing from then on.

Resource GPS Tracking

Requirements

  • The endpoint of interest is either https://api.dimescheduler.com/resourceGpsTracking, or https://sandbox.api.dimescheduler.com/resourceGpsTracking for the sandbox environment.
  • You'll need an API key to invoke this endpoint.
  • To run the script below, you must install HTTPie. We use HTTPie because it's succint and clean, but any HTTP client or CLI tool such as Postman and cURL will do, as long as they can make HTTP POST requests. You can always use our SDKs and CLI for these tasks as well.
  • Set the location mode of the map to "Actual location" in the layers menu at the top-right corner of the map component.

The script

# Set these variables
$key = 'YOUR API KEY GOES HERE'
$resourceNo = 'THE RESOURCE NUMBER GOES HERE'

# Set of coordinates around New York's Central Park
$coordinates = @(
(40.768989, -73.981252),
(40.772393, -73.978810),
(40.775322, -73.976642),
(40.778077, -73.974745),
(40.782615, -73.971368),
(40.787153, -73.967980),
(40.791478, -73.964905),
(40.798254, -73.959996),
(40.799872, -73.958773),
(40.800017, -73.956635),
(40.799102, -73.954424),
(40.797941, -73.951653),
(40.796234, -73.949751),
(40.794612, -73.950820),
(40.793887, -73.951454),
(40.791395, -73.953256),
(40.788493, -73.955364),
(40.786373, -73.956897),
(40.784124, -73.958607),
(40.783633, -73.958905),
(40.781138, -73.960833),
(40.779300, -73.962090),
(40.776249, -73.964257),
(40.772280, -73.967290),
(40.768403, -73.970025),
(40.765863, -73.971855),
(40.765292, -73.975203),
(40.766593, -73.978481),
(40.767629, -73.980935)
)

# Every 5 seconds, the API is invoked
Foreach ($coordinate in $coordinates)
{
$lat = $coordinate[0]
$lng = $coordinate[1]
http -v POST https://sandbox.api.dimescheduler.com/resourceGpsTracking X-API-KEY:$key resourceNo=$resourceNo latitude=$lat longitude=$lng
timeout 5
}

The script's outline looks as follows:

  • Initiate the $key and $resourceNo variables. You must set these, otherwise the script won't work.
  • Create a sample set of coordinates. In this case, we'll go for a quick run around New York's Central Park.
  • Loop through these coordinates and wait 5 seconds before continuing with the next iteration.

Using HTTPie's minimalistic syntax, we can update the location with one single line of code:

http -v POST https://sandbox.api.dimescheduler.com/resourceGpsTracking X-API-KEY:$key resourceNo=$resourceNo latitude=$lat longitude=$lng

The script makes a HTTP POST request to https://sandbox.api.dimescheduler.com/resourceGpsTracking and provides 4 data fields:

  • X-API-KEY is added to the headers and is required to make the request. Otherwise a 401 error will be thrown.

  • resourceNo, latitude and longitude are passed in the request's body as a JSON object:

    {
    "ResourceNo": "YOURRESOURCENO",
    "Latitude": YOURLATITUDE,
    "Longitude": YOURLONGITUDE,
    }

After invoking the command, Dime.Scheduler will push the update to the browser sessions as well.