/ product

Live location tracking with Node.js and Python

Product development teams around the world are creating applications powered by real-time location tracking. Now these teams have the power at their fingertips, to control tracking of mobile devices from the cloud, with Node.js and Python. This functionality is delivered through RESTful Devices and Trips APIs that can start and stop tracking on any app built with HyperTrack.

Many of you developers favor programming languages such as Node.js and Python. To make it simpler, easier, and faster for you to start using Devices and Trips APIs and get your movement tracking applications to production, we are announcing the release of our helper libraries for Node.js and Python.

Helper libraries for Node.js and Python come with convenient abstractions that hide explicit HTTP API calls, and offer intuitive and easy-to-use classes to write and ship production code in a matter of minutes.

Getting started with Node.js helper library

In order to get started with Node.js helper library, you may install the hypertrack module with npm:

npm install hypertrack

Once you install the module, you will need to initialize your helper instance as shown below. Your credentials are available at your account dashboard setup page.

const hypertrack = require('hypertrack')(account_id, secret_key);

Now, you are ready to start and stop device tracking with Devices API, or start and complete trips with Trips API. Developers use Devices to simply track devices during certain hours or perpetually, and Trips to track ETAs going to a destination, or routes to geofences. For more detail on these APIs, read our guides for tracking devices with the API, tracking trips with destinations, and tracking trips with geofences.

In the examples below, you may use a device identifier for any app built with HyperTrack, including the HyperTrack Live app you downloaded from the Play Store or App Store after signing up.

Devices

Start location tracking on your device by calling this method:

hypertrack.devices.startTracking(device_id)

To stop tracking on your device, go ahead and call this method:

hypertrack.devices.stopTracking(device_id)

Trips

To start a trip with destination, use the following code snippet:

hypertrack.trips.create({
    device_id: device_id,
    destination: {
    geometry: {
      type: "Point",
      coordinates: [-122.398096, 37.793038]
    },
    scheduled_at: "2022-05-03T06:25:51.238000Z"
  },
  metadata: {
    shift_id: "ABC123"
  }
})
.then((trip) => console.log(trip));

At some point in your application workflow, when you decide to complete this trip by using trip identifier from above, use the following code snippet:

hypertrack.trips.complete(
    trip_id
)
.then((message) => console.log(message));

Getting started with Python helper library

In a similar fashion, we are offering easy to use packages for the Python development community.

Python helper library source is available via pip install:

pip install hypertrack

Once you install the package, you will need to initialize your Python instance as shown below. Your credentials are available at your account dashboard setup page.

from hypertrack.rest import Client

account_id = "your_account_id"
secret_key  = "your_secret_key"

client = Client(account_id, secret_key)

Devices

Start location tracking on your device as shown in the example below:

client.devices.start_tracking(device_id)

To stop tracking on your device, go ahead and call this method:

client.devices.stop_tracking(device_id)

Trips

To start a trip with destination, use the following code snippet:

trip = client.trips.create({
    "device_id": device_id 
    "destination": {
        "geometry": {
            "type": "Point",
            "coordinates": [-122.398096, 37.793038]
        },
    "scheduled_at": "2022-05-03T06:25:51.238000Z"
    },
    "metadata": {
        "shift_id": "ABC123"
    }
})

At some point in your application workflow, when you decide to complete this trip by using trip identifier from above, use the following code snippet:

client.trips.complete(trip["trip_id"])

API reference with helper libraries

The snippets above are just some examples of functionality that devices and trips modules offer you. For more information on additional methods, please visit API references and select the Node.js or Python language switchers for code snippets.

HyperTrack is becoming the default way for product development teams to build live location apps for business. Use these helper libraries to build your use case and join over ten thousand developers around the globe building workforce automation, fleet management, logistics, on-demand delivery, gig economy, ridesharing and other apps with HyperTrack.

Contribute

I would like to invite you to contribute to the developer community by adding more to current libraries (Node.js and Python), or adding libraries that you would like to see the community build with.

We are continually making improvements and adding more functionality to make development of movement tracking applications fun, and empower you with tools to make location tracking programmable from the cloud.

Feel free to reach out for comments, suggestions, or questions to us at help@hypertrack.com or join our Slack support community.