Skip to main content

Updating the actual locations of resources

Feed live GPS coordinates from tracking devices into Dime.Scheduler so each resource shows up at its real-world location on the map.

The map can display a resource's location from two types of addresses:

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

Static addresses travel with the Resource entity. Dynamic addresses have their own entity, ResourceGpsTracking. Any system that can make an HTTP POST request can call this API to push a resource's last known location to the map.

To update a resource's current location, provide three properties:

  • The Resource No
  • The latitude
  • The longitude

Location trackers provide the coordinates and an identifier for the tracker, but not the Dime.Scheduler resource number. So you'll need to maintain a list that maps each tracking device to its resource number. Once that mapping is in place, the rest is straightforward.

Resource GPS Tracking

Requirements

  • The endpoint is https://api.dimescheduler.com/resourceGpsTracking, or https://sandbox.api.dimescheduler.com/resourceGpsTracking for the sandbox environment.
  • You'll need an API key to call this endpoint.
  • To run the script below, install HTTPie. We use HTTPie because it's succinct and clean, but any HTTP client or CLI tool such as Postman and cURL will do, as long as it can make HTTP POST requests. Our SDKs and CLI handle these tasks as well.
  • Set the map's location mode 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
}

Here's what the script does:

  • Sets the $key and $resourceNo variables. You must fill these in, otherwise the script won't run.
  • Defines a sample set of coordinates. This example traces a quick run around New York's Central Park.
  • Loops through the coordinates, waiting 5 seconds between each iteration.

With HTTPie's minimal syntax, a single line updates the location:

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

The script makes an HTTP POST request to https://sandbox.api.dimescheduler.com/resourceGpsTracking with four data fields:

  • X-API-KEY is added to the headers and is required. Without it, the request returns a 401 error.

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

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

After the command runs, Dime.Scheduler pushes the update to open browser sessions as well.