All Collections
User Guides
How to create a real-time map?
How to create a real-time map?

Properly send location data so it can be displayed in Ubidots

David Sepúlveda avatar
Written by David Sepúlveda
Updated over a week ago

Yes! You can use Ubidots to display real-time location of devices. To do so, you need to specify the latitude ("lat") and longitude ("lng") in the "context" of your request. So instead of sending this:

{"value":20}

The payload should look like this:

{"value":20,"context":{"lat":40.782864,"lng":-73.965355}}

Examples

Requests Without Location Data

Typically, this is the payload you send to Ubidots to record sensor data:

Using API Labels

curl -X POST -H "Content-Type: application/json" -d '{"temperature": 20}' https://industrial.api.ubidots.com/api/v1.6/devices/weather-station?token={YOUR-TOKEN}

Using Variable IDs

curl -X POST -H "Content-Type: application/json" -d '{"value": "20"}' https://industrial.api.ubidots.com/api/v1.6/variables/58f43a9e76254254ab679476/values?token={YOUR-TOKEN}

These requests will create a single data point in the "Temperature" variable:

Requests With Location Data

If you want to add location data, then you should add a "context" property with these keys:

  • "lat"

  • "lng"

These are case-sensitive! If written differently, the Map widget won't recognize them as location points! Here the above examples but with location data:

Using API Labels

Body of the request: 

{"temperature": {"value":20,"context":{"lat":40.782864,"lng":-73.965355}}}

HTTP Request:

curl -X POST -H "Content-Type: application/json" -d '{"temperature": {"value":20,"context":{"lat":40.782864,"lng":-73.965355}}}' https://industrial.api.ubidots.com/api/v1.6/devices/weather-station?token={YOUR-TOKEN}

Using Variable IDs

Body of the request: 

{"value":20,"context":{"lat":40.782864,"lng":-73.965355}}

HTTP Request:

curl -X POST -H "Content-Type: application/json" -d '{"value":20,"context":{"lat":40.782864,"lng":-73.965355}}' https://industrial.api.ubidots.com/api/v1.6/variables/58f43a9e76254254ab679476/values?token={YOUR-TOKEN}


Any of these requests will create a data-point with a lat and lng context properties:

Which can be then read by a Map widget. This can be created in your dashboard --> Add new widget --> Map Widget --> Select the device that contains Position (Lat & Long) Properties.

Expectations for Visualization

It is important to note that the Ubidots real-time map display is a live interface. When you select to view a historical range of data in the Map, your historical data will appear as a "trace." Any incoming real-time data will appear as a smooth "line". 

Did this answer your question?