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":10}

The payload should look like this:

{"value":10,"context":{"lat":51.5,"lng":-0.11}}}

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": 10}' http://things.ubidots.com/api/v1.6/devices/weather-station?token={YOUR-TOKEN}

Using Variable IDs

curl -X POST -H "Content-Type: application/json" -d '{"value": "10"}' http://things.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":10,"context":{"lat":51.5,"lng":-0.11}}}

HTTP Request:

curl -X POST -H "Content-Type: application/json" -d '{"temperature": {"value":10,"context":{"lat":51.5,"lng":-0.11}}}' http://things.ubidots.com/api/v1.6/devices/weather-station?token={YOUR-TOKEN}

Using Variable IDs

Body of the request: 

{"value":10,"context":{"lat":51.5,"lng":-0.11}}

HTTP Request:

curl -X POST -H "Content-Type: application/json" -d '{"value":10,"context":{"lat":51.5,"lng":-0.11}}' http://things.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 variable containing lat and lng properties in context.

Keywords: GPS, Map, Location, Position.

Did this answer your question?