Skip to end of metadata
Go to start of metadata

Scenario

  1. A "GPS" thing will be created with a "locationChanged" event
  2. The "locationChanged" event refers to a "Location" data structure, which consists of latitude and longitude values
  3. This event will be activated by UI in this example, but it can also be activated by API, method logic, script property, another trigger, or schedule
  4. Two mapping widgets will be created: "GPS position" and "GPS trait"
  5. All "Location" data from the "locationChanged" event will be used as the "Location Source" for the mapping widgets
  6. This example describes how the "GPS" thing can be used to get directions while taking a walk in the city of Rome
  7. A dashboard is created for the widgets, where detailed maps can be visualized for current "GPS" location and trait

Prerequisites:

  1. Mapping characteristics can be set when creating a widget:
    1. Map Layer: Map, Satellite, Hybrid, and Terrain
    2. Map Zoom: Automatic (AUTO) or settable from 1 to 20
    3. Refresh rate in seconds (0 seconds = no refresh)
  2. Multiple "Location" values can be entered in an event, forming a JSON array
  3. Each "Location" value must include a time stamp (time of occurrence) when pushing an event

Steps

1. Create "GPS" thing


  1. In the "Things" tab, open "Create Thing" dialog
  2. Set the name as "GPS", and choose the icon
  3. Save thing by clicking "Save"

2. Create "locationChanged" event


  1. In the "Thing: GPS" tab, open "Events"
  2. Click "New" to open "Create Event" dialog
  3. Set name to "locationChanged"
  4. Set data type to "Location" by:
    1. clicking the [...] button on the right of "Data Type" input
    2. Click "more types in the drop-down menu to open the "Select Type" dialog
    3. Start typing "location" in the search field to locate the data type
    4. In the "Matching items" list, select the "Location" data type
    5. Click "Select" to enter this structured data type in the "Data Type" field
  5. Save new event by clicking "Save"

The "locationChanged" event refers to the "Location" data structure, which consists of two double type values: lat and lng (latitude and longitude)

3. Fire "locationChanged" event using UI


  1. In the "Events" section of the "Thing: GPS" tab, select "locationChanged"
  2. Click "Push Event" to open dialog
  3. Insert the following JSON formatted data structure in the text area

  4. Click "Push" to activate the event

This code is actually an array of two JSON objects, each of which contains a "Location" data structure along with a time of occurrence

4. Create "GPS" dashboard


  1. Open "Dashboards" in main menu to show list of dashboards
  2. In the dashboards list, click "+" to show "Create Dashboard" dialog
  3. Set the name to "Temperature"
  4. Click "Save" to save new dashboard

5. Create "GPS position" widget

  1. In the "Dashboard: GPS" tab, click "Add Widget" to open drop-down menu
  2. Click "Map Position" in this menu to open the "Settings" dialog
  3. Set "Title" to "GPS position"
  4. Set "Thing" to "GPS"

  5. Set "Location source" to "Event"

  6. Set "Event" to "locationChanged"
  7. Set "Map Zoom" to "18"
  8. Set "Refresh rate" to "10"
  9. Click "Save" to save the new widget for displaying GPS position on a map

The "GPS position" widget will immediately appear, and show the current position on a map based on data from the most recent "locationChanged" event


6. Create "GPS trait" widget


  1. Click "Add Widget" to open drop-down menu
  2. Click "Map Trait" in this menu to open the "Settings" dialog
  3. Set "Title" to "GPS trait"
  4. Set "Thing" to "GPS"

  5. Set "Event" to "locationChanged"

  6. Set "Trait history" to "Starting the last event"
  7. Set "Trait history, hours" to "1"
  8. Set "Map Zoom" to "20"
  9. Set "Refresh rate" to "10"
  10. Click save the new widget for displaying GPS trait on a map

The "GPS trait" widget will chart the route taken by a user based on "Location" data from "locationChanged" events. The route is plotted sequentially for all "Location" data obtained within the "Trait history" time range up to the current position. "Trait history" is set to 1 hour, but this can be changed as needed.





  • No labels