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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

How to convert two numbers to a location datatype?

aheinz
1-Newbie

How to convert two numbers to a location datatype?

Hello Community,

i have problems with the datastructure of location datatype. The problem is, that i have two variables with the datastructure of a number (var latitude; var longitude) and want to combine them to datatype of a location. I've tried several things but failed. My goal is to combine variables of datatype number for latitude and longitude in a service to get an infotable which i can connect to the google maps widget in the mashup, that will show me the routes.

I hope that you can give me an advice to achiv this or show me a way how i can write a variable of datatype location directly in a service.

1 ACCEPTED SOLUTION

Accepted Solutions
nkhose
1-Newbie
(To:aheinz)

Hi ,

I think not using infotable as output but use location as output  and you have latitude and longitude  you can create location obeject as

var location = new Object();

location.latitude = -111.2255859375;

location.longitude = 55.27911529201562;

location.elevation = 0;

location.units ="WGS84";

var result = location;

and then bind to map widget i suppose , Hope this helps

View solution in original post

5 REPLIES 5
supandey
19-Tanzanite
(To:aheinz)

Hi,

Is there a reason why you are using Number instead of Double datatype? AFIK LOCATION datatype is expecting Double datatype. Could you explain a bit from where you getting the Locations, is it auto generated or is it tied to a remote thing? Are there any errors in your service when you trying to combine them?

Here it is just to extend bit more on the Location

nkhose
1-Newbie
(To:aheinz)

Hi ,

I think not using infotable as output but use location as output  and you have latitude and longitude  you can create location obeject as

var location = new Object();

location.latitude = -111.2255859375;

location.longitude = 55.27911529201562;

location.elevation = 0;

location.units ="WGS84";

var result = location;

and then bind to map widget i suppose , Hope this helps

oschenk
1-Newbie
(To:nkhose)

I can't get this to work. My steps are as follows:

1) SQL Query service called "getSitesQuery" to query a database - this works

This returns an INFOTABLE based on a DataShape.

Columns include "Lat" and "Lon" each with type NUMBER

The DataShape has an additional column called "GPSLocation" with type LOCATION.

2) I then have a script which calls this query above and tries to populate the GPSLocation field for each row by using the Lat and Lon columns to create the location. However, I'm struggling to get this to work. When I click on the "Test" button in the composer it just comes back with "NaN : NaN" for the GPSLocation column.

// result: INFOTABLE dataShape: "xNetConfig_XSite"

var sitesTable = me.getSitesQuery();

var tableLength = sitesTable.rows.length;

for (var x = 0; x < tableLength; x++) {

      

    var location = new Object();

    location.latitude = sitesTable.rows.Lat;

    location.longitude = sitesTable.rows.Lon;

    location.elevation = 0;

    location.units ="WGS84";

  

    sitesTable.rows.GPSLocation = location;

}

result = sitesTable;

3) I try to bind the result of the above to an OpenStreetMap widget I just get the error:

I don't understand why the error talks about 'lat' of undefined. I'm assuming OpenStreetMaps is looking for "lat" but not sure where...

15:02:04 ERROR - Runtime exception handling data update for binding {"Id":"35740636-782f-4f95-8e04-6eedaec8e663","SourceArea":"Data","SourceSection":"Things_xConfig","SourceId":"getSites","SourceDetails":"AllData","TargetArea":"UI","TargetSection":"","TargetId":"OpenStreetMap-1","PropertyMaps":[{"SourceProperty":"","SourcePropertyType":"InfoTable","SourcePropertyBaseType":"INFOTABLE","TargetProperty":"Data","TargetPropertyType":"property","TargetPropertyBaseType":"INFOTABLE"}],"isBoundToSelectedRows":false} Exception: Cannot read property 'lat' of undefined


tguo
4-Participant
(To:oschenk)

Hi, Is the problem solved? I also get the problem of NaN:NaN in the location field..

GaryLHinkle
5-Regular Member
(To:aheinz)

If you are using a grid you can use the configure grid columns and select the attribute that is your location variable. Select the column Renderer and State Formatting tab. Now change the decimal format from 0.0000 to 0.00000000 or the number of decimals you need. I tested this on TW8 so hopefully it will work on older version.

Top Tags