cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Create location data

TW_Student
Participant

Create location data

Hello everyone,

 

I'm a student and I'm working on a project using Thingworx.

I would like to display multiple locations of several cars (with multiple pins representing each car, on a map). These cars are totally virtual, I don't have real data yet.

First I would like to know how to create "fake" location data. Then I would like to get more details on how to display these locations on the map. (I have read through several topics which were way too brief for beginners like me).

 

Until now, I have created a Mashup with a location pointed on a map (via OpenStreetMap) but the data is only from the default value that I set up in my ThingTemplate (whose property is Location).

 

Thanks for your help

 

2 REPLIES 2

Re: Create location data

Create a thing that you will use to create a service (or if you already have a thing, just create a new service).  Call your service GetLocations or whatever you want.  Set it's output type to infotable.  Create a new Datashape and add a string property for name or ID or whatever you want to call it and another location property of type Location.  Set your service to use this datashape for your infotable output.  

 

Use the snippets to create a new instance of an infotable based on your custom datashape.  Also use the snippets to create a new entry for your infotable based on your datashape.  Fill in the values for your name/id and your location attributes.  Then add that entry to your infotable (

 

var newEntry={};

newEntry.name="car1";

newEntry.location={"lat":12345, "long":45678, "elevation": 0};

result.AddRow(newEntry))

 

Repeat the above code for as many entries as you'd like to show on your map.  

Re: Create location data

Thank you for your quick reply!

What do you mean by "Use the snippets to create a new instance of an Infotable based on your custom Datashape. Also use the snippets to create a new entry for your Infotable based on your Datashape. Fill in the values for your name/id and your location attributes." ? Do you mean that I must click on Create Infotable entry from Datashape and Create Infotable from Datashape (then it automatically adds some code)?

As soon as I have done these steps, how am I able to implement this in my Map Mashup? I think I must add the thing I created in "Add Data" and select the service "GetLocation"?

I'm using OpenStreetMap given that the Google Maps widget is not working (It could apparently work only if I pay for getting an API code)

Here is the code in the script:

 

var params = {

               infoTableName : "InfoTable",

               dataShapeName : "Datashape_for_GetLocations"

};

 

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(Datashape_for_GetLocations)

var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

 

// Datashape_for_GetLocations entry object

var newEntry = new Object();

newEntry.Car_ID = undefined; // STRING

 

 

var newEntry={};

newEntry.name="car1"

newEntry.location={"lat":12,"long":0,"elevation":0};

result.AddRow(newEntry);

 

 

var newEntry={};

newEntry.name="car2"

newEntry.location={"lat":45,"long":0,"elevation":0};

result.AddRow(newEntry);

 

Is the script correct ?

 

 

Finally, you can see my mashup (picture attached), obviously there is an error …

I don't have any input in the Service "GetLocation", is this the source of my problem ?

Announcements

Check out the upcoming Expert Session: Understanding ThingWorx Navigate Licensing in Community "Customer Events" section.