Geolocation

Track a delivery fleet in real time

Dispatch delivery vans on a live map and watch their location and cargo temperature update. Message a driver, reboot a sensor, or send a vehicle somewhere new. Built with plain JavaScript and the PubNub JavaScript SDK.

The Transportation & Logistics demo: two delivery vans on a map of San Francisco with their routes, and the list of registered vehicles with next delivery, ETA, and cargo temperature
About this demo

A dispatch dashboard in your browser tab

The Transportation & Logistics demo is built with plain JavaScript, Google Maps, and the PubNub JavaScript SDK. The vehicles are simulated: each one runs in its own web worker with its own PubNub client, so every position, reading, and command really travels over PubNub, just as it would from a device in a truck.

Vehicles publish route updates as messages and send their position and temperature as signals. The dashboard listens to every vehicle with one wildcard subscription to vehicle.*, and sends commands back on each vehicle's own channel. Presence shows whether a sensor is online, Message Persistence lets a new window catch up on vehicles already on the road, and Access Manager tokens control access. Vehicles start near PubNub's San Francisco office, or near you if you tick Localize and allow location access. The source code is open on GitHub.

Features

What you can do

  • Dispatch a vehicle

    Press Dispatch Vehicle and a delivery van starts a route with four stops. Its first message draws the route on the map. You can run up to three vehicles at once.

  • Follow location and temperature

    Every half second, each vehicle sends two small signals: its position and a cargo temperature reading. The van moves along its route, and the ETA and reading update in the list.

  • Message the driver

    Open a vehicle and send the driver a message. It goes to the vehicle's own channel and shows up next to the van on the map. The driver's phone is simulated here.

  • Reboot a temperature sensor

    Reboot the sensor and it leaves the channel. Presence marks it offline in the list. About five seconds later it rejoins and turns green again.

  • Redirect a vehicle

    Choose Redirect Vehicle and the dashboard publishes a new route to the van. It ends its current leg and drives from where it is to a new destination.

  • Catch up on vehicles on the road

    Open the dashboard again with the same identifier and it fetches recent messages from history. Vehicles that are mid-route reappear and keep moving.

Build it yourself

Make your own logistics dashboard

Clone the app, add your PubNub keys and a Google Maps API key, and run it locally.

GitHub

PubNubDevelopers/transport-logistics-javascript-demo

The complete source. Enable Presence, Stream Controller, and Message Persistence on your keyset, add your keys and Google Maps API key to js/keys.js, then serve the folder with any local web server, for example python3 -m http.server 8080.

git clone https://github.com/PubNubDevelopers/transport-logistics-javascript-demo.git
View on GitHub
Keep building

Build interactive real-time experiences with PubNub

Bring chat, live updates, and real-time interactions into your application without building the infrastructure from scratch.