Location tracking
Location actions capture a position and write it directly to an entity — no rule chain and no custom JavaScript required. You configure a target entity and a set of data keys once, and the platform saves latitude, longitude and the other location fields under those keys as server attributes or time series.
Available actions
Section titled “Available actions”| Action | Action type | Runs in | Saves |
|---|---|---|---|
| Save browser location | Widget action | Any widget, in a web browser | One position, read from the browser when the action is triggered |
| Get phone location | Mobile action | ThingsBoard Mobile Application | One position, read from the phone. Saving is optional and off by default |
| Start live location tracking | Mobile action | ThingsBoard Mobile Application | A stream of positions until the session ends |
| Stop live location tracking | Mobile action | ThingsBoard Mobile Application | Nothing — ends the running tracking session |
Configuration
Section titled “Configuration”The Target panel and the Keys that are saved to entity table are configured the same way in every action that writes a position. Accuracy and Session limits are available in Start live location tracking only.
Every location action writes to exactly one entity, configured in the Target panel. The panel has two modes, selected with the toggle in its top-right corner.
Target entity
Section titled “Target entity”The target is the entity itself. Pick it in the Save to drop-down:
| Source | Resolves to |
|---|---|
| Entity from widget datasource | The entity the widget action was triggered on — the row you clicked, the marker you tapped, and so on |
| Current user | The user account that triggered the action |
| Entity alias | The entity resolved from a dashboard entity alias. Enter its name in Alias name |
Target from attribute
Section titled “Target from attribute”The target is not the entity itself, but a second entity, whose id is stored in a server attribute of the first. Use this when the widget shows one entity but the location belongs to another — for example, a technician’s dashboard row pointing at the vehicle assigned to them.
- Switch the Target toggle to From attribute.
- In Read attribute from, choose the entity that holds the attribute — Entity from widget datasource, Current user, or Entity alias. For Entity alias, enter its name in Alias name.
- In Server attribute key, enter the attribute name.
The attribute must hold an Entity Id object with both fields, for example:
{ "entityType": "DEVICE", "id": "784f394c-42b6-435a-983c-b7beff2784f9"}A plain id string is not accepted.
Saved keys
Section titled “Saved keys”The Keys that are saved to entity table maps each location field to a Data key name and a Type — Server attribute or Time series.
| Field | Default data key | Default type | Required |
|---|---|---|---|
| Latitude | latitude |
Server attribute | Yes |
| Longitude | longitude |
Server attribute | Yes |
| Accuracy | gpsAccuracy |
Time series | No |
| Altitude | gpsAltitude |
Time series | No |
| Speed | gpsSpeed |
Time series | No |
| Heading | gpsHeading |
Time series | No |
| GPS active | gpsActive |
Server attribute | No |
| GPS tracked by user | gpsTrackedBy |
Server attribute | No |
A new action starts with Latitude and Longitude only. Add the rest with Add key, and remove any optional key with the bin icon. Latitude and longitude cannot be removed, and data keys must be unique within one action. Altitude, Speed, Heading, GPS active, and GPS tracked by user can only be added to a Start live location tracking action.
Rename a data key whenever the target entity already uses a different convention — a map widget reading lat and lng, for example. Choosing Time series instead of Server attribute keeps the full history of a value rather than only its latest state, which is what you want for a track you intend to plot.
Accuracy
Section titled “Accuracy”Available in Start live location tracking only, under Advanced settings. Accuracy is the trade-off between how precise each position is and how much battery tracking consumes.
| Accuracy | How a position is obtained | Best for |
|---|---|---|
| High | GPS — around 5 m | Vehicle or field-worker tracking. Drains the battery fastest |
| Balanced (default) | Wi-Fi and cell towers, falling back to GPS only when needed — around 40 m | Periodic check-ins at moderate battery cost |
| Low | Cell towers only — around 500 m or worse | City-level presence over long periods, with minimal battery use |
Session limits
Section titled “Session limits”Available in Start live location tracking only, under Advanced settings. Each limit has its own toggle; the value field and its Units drop-down appear only once the toggle is on.
| Field | Limit | Minimum | Effect |
|---|---|---|---|
| Distance | Limit updates by travelled distance | 1 meter | Skips updates until the device has moved at least this far from the previously reported position |
| Interval | Limit updates by time interval | 1 second | Requests a new position no more often than this. Without it, updates arrive as fast as the device reports them |
| Duration | Stop tracking after a maximum duration | 1 minute | Tracking stops by itself once this much time has passed since it started |
Leaving every limit off means the app reports positions as fast as the device produces them and keeps the session running until someone stops it — accurate, and the most expensive option for the battery.
Save browser location
Section titled “Save browser location”Reads the browser’s geolocation once when the action is triggered and saves it to the target entity. The mobile app is not involved, so this action works in any widget on any dashboard opened in a browser.
- Open the widget in edit mode, go to the Actions tab, and click +.
- Select the action source, enter a name, and choose an icon.
- Select Save browser location as the action type.
- Configure the Target panel and the Keys that are saved to entity table.
- Click Add, then Apply to save the widget settings.
- Click Save in the dashboard toolbar.
The browser asks the user for location permission the first time the action runs.
On success the user sees a Browser location saved notification. Failures are reported as:
| Message | Cause |
|---|---|
| This browser does not support location detection | The browser exposes no geolocation API |
| Browser location requires a secure (HTTPS) connection | The dashboard is served over plain HTTP |
| Location permission was denied | The user dismissed or blocked the browser permission prompt |
| Current location is unavailable | The browser could not determine a position |
| Timed out while getting the current location | No position was returned in time |
Get phone location
Section titled “Get phone location”An existing mobile action that reads the phone’s current position and passes it to a JavaScript function. It now also has an optional Save location to entity toggle.
- Open the widget in edit mode, go to the Actions tab, and click +.
- Select the action source, enter a name, and choose an icon.
- Select Mobile action as the type, then Get phone location as the mobile action type.
- Turn on Save location to entity, then configure the Target panel and the Keys that are saved to entity table.
- Click Add, then Apply, then Save in the dashboard toolbar.
With the toggle off the action behaves exactly as before — the coordinates reach your processLocation function and nothing is written. Existing actions are unaffected by the upgrade.
Start live location tracking
Section titled “Start live location tracking”Hands a fully resolved configuration to the ThingsBoard Mobile Application, which then owns the session: it streams GPS fixes — including while the app is in the background — and writes each one to the target entity itself.
- Open the widget in edit mode, go to the Actions tab, and click +.
- Select the action source, enter a name, and choose an icon.
- Select Mobile action as the type, then Start live location tracking as the mobile action type.
- Configure the Target panel and the Keys that are saved to entity table.
- Expand Advanced settings to set the accuracy and the session limits. All three limits are off by default.
- Click Add, then Apply, then Save in the dashboard toolbar.
Stop live location tracking
Section titled “Stop live location tracking”Ends the tracking session currently running in the mobile app. It has no target or key configuration of its own — the session already knows where it writes.
- Open the widget in edit mode, go to the Actions tab, and click +.
- Select the action source, enter a name, and choose an icon.
- Select Mobile action as the type, then Stop live location tracking as the mobile action type.
- Click Add, then Apply, then Save in the dashboard toolbar.
A session can also be stopped from the app itself, so a stop action on the dashboard is a convenience rather than a requirement.
Both live tracking actions come with a default result-handler function that shows a confirmation dialog. The function receives launched — whether the session actually started or stopped — and, for the start action, trackingInfo with the target entity name. Replace the body with your own logic, or empty it to show nothing.
Was this helpful?