Search code examples
javascriptgoogle-mapsgoogle-maps-api-3iotthingworx

How to simulate position tracking of an iot thing?


I need to simulate the position tracking for my 'IoT thing' in my IoT platform Thingworx. For eg: If I have a car as a Thing, and it has two modes moving and stopped. I need to simulate the changing latitude and longitude for the car when it is in 'moving' state and store the generated coordinates so that they can be later displayed on the Google map widget in the mashup. Similarly, if the car is stopped then it should display the location where it was last stopped. I have the following questions:

  1. How do I achieve this? As in, should I create and use a service or a subscription (with speed values as the trigger)?
  2. What sort of code snippet will be required for such a functionality?
  3. Should I employ the Google api?
  4. Also how do you store the changing values of the lat/long in the variable which has a datatype 'Location'?

Thanks!


Solution

  • A part of the logic to simulate movement, which can be as complex as you want or a simple as adding Randomly movements to the Latitude / Longitude.

    1. You should use a Timer Thing which for instance triggers every second ( or any other frequency ) and you subscribe to "Timer" event and there you write the code to move the car.

    2. You need to have a property on the Car Thing that we can call it "location" which of baseType LOCATION, and this property should be set as "logged" then you just need to update location property with the new location ( if it moved since last location - on your simulator code - ). Of course you also must set car Thing's ValueStream property in order to get storage for location changes.

    3. You can use TW Marketplace Google Maps extension in order to show Location and Paths on Google Maps from the recorded simulation.

    4. Setting a location property in TW it's something like:

    me.location = { latittude: latitude_value, longitude: longitude_value, elevation: elevation_value, units: "WGS84" }

    Hope it helps.