Sending Location Data to Device Cloud in Python

A client application can send geolocation data to Device Cloud using the location API to monitor the device location.

You need a wireless network adapter or GPS antenna and the associated drivers that are compatible with your board. For more information about the supported boards and hardware, see the information for the supported operating systems.

If you use a wireless network for location data, you need software libraries on your device to access geolocation data from a service provider, such as Google. Depending on your service provider, you may need a commercial subscription.

Before you run your application, the thing definition that corresponds to your application must be defined.

To send data to Device Cloud, the application must be connected to Device Cloud.

Publish the location.

Retrieve the location data from your geolocation service provider, GPS antenna, or use fixed values.

Specify latitude and longitude as decimal values.

Optionally, specify any other location properties.

client.location_publish(latitude, longitude, heading=heading, speed=speed)

When your application runs, the application transmits the location data to Device Cloud. If the location source is not in the Fix types to ignore list in the thing definition, the thing details page shows the new location and the device position on the map changes.

Example Code

The iot-simple-location.py sample application provided with the agent shows example code for transmitting location data.