Skip to main content
18-Opal
June 1, 2017
Solved

Help me Please.. About NaN

  • June 1, 2017
  • 1 reply
  • 3945 views

Retrieves data from the database

If the longitude value is 0, the previous GPS value is obtained.

If the longitude value is not 0 in the database, the distance is obtained

However, if the longitude value is 0, it is output as NaN

and GPSvalue was obtain when longitude value is 0

but distance is not obtain when longitude value is 0

why? i don't know... T^T

Help me.. Thanks...

and attach my code

var params = {

datetime: w /* DATETIME */,

cdma_number: me.cdma_number /* STRING */

};            // result: INFOTABLE dataShape: TruckDataFeildDataShape

var TruckData = Things["GetTruckDateFromPostgreDB"].GetTruckData(params);

var params = {

  oldestFirst: true /* BOOLEAN */,

  maxItems: undefined /* NUMBER */,

  endDate: undefined /* DATETIME */,

  query: undefined /* QUERY */,

  startDate: w /* DATETIME */

};

// result: INFOTABLE dataShape: "undefined"

var AAA = me.QueryPropertyHistory(params);

var pre = AAA.getRow(0);

var GPS = new Object();

var params = {

datetime: TruckData.kst_datetime /* DATETIME */,

cdma_number: "01088948133" /* STRING */

};

// result: INFOTABLE dataShape: TruckDataFeildDataShape

var preEntry = Things["GetTruckDateFromPostgreDB"].CompareTruckData(params);

var PGPS = new Object();

if(preEntry.latitude ==0){

PGPS=pre.GPS;

}

else{

PGPS.latitude = parseInt(preEntry.latitude/100)+(preEntry.latitude - parseInt(preEntry.latitude/100)*100)/60;

PGPS.longitude= parseInt(preEntry.longitude/100)+(preEntry.longitude - parseInt(preEntry.longitude/100)*100)/60;

PGPS.elevation = 0;

PGPS.units = "WGS84";

}

if(TruckData.latitude ==0){

GPS = PGPS}

else{

GPS.latitude = parseInt(TruckData.latitude/100)+(TruckData.latitude - parseInt(TruckData.latitude/100)*100)/60;

GPS.longitude= parseInt(TruckData.longitude/100)+(TruckData.longitude - parseInt(TruckData.longitude/100)*100)/60;

GPS.elevation = 0;

GPS.units = "WGS84";

}

// distanceBetween(loc1:LOCATION,loc2:LOCATION,units:STRING):NUMBER

// distanceBetween(loc1:LOCATION,loc2:LOCATION,units:STRING):NUMBER

var difference = distanceBetween(GPS, PGPS, "");

Best answer by posipova

I would try outputting that value to ensure it exists in a correct form first, perhaps in a separate service just to test it. Or assign the result to it and output it.

Also look into using try/catch JavaScript Errors Try Catch Throw

1 reply

20-Turquoise
June 1, 2017

I might be missing this/not seeing but for this piece, where are you defining/setting pre.GPS?

var PGPS = new Object();

if(preEntry.latitude ==0){

PGPS=pre.GPS;

}

CHASEONHO18-OpalAuthor
18-Opal
June 1, 2017

Dear Polina Osipova

var params = {

  oldestFirst: true /* BOOLEAN */,

  maxItems: undefined /* NUMBER */,

  endDate: undefined /* DATETIME */,

  query: undefined /* QUERY */,

  startDate: w /* DATETIME */

};

// result: INFOTABLE dataShape: "undefined"

var AAA = me.QueryPropertyHistory(params);

var pre = AAA.getRow(0);

i logging GPS value when GPS.longitude value wasn't 0

and w is last receive time

so i get before GPS data when now GPS.longitude value is 0

thanks

posipova20-TurquoiseAnswer
20-Turquoise
June 1, 2017

I would try outputting that value to ensure it exists in a correct form first, perhaps in a separate service just to test it. Or assign the result to it and output it.

Also look into using try/catch JavaScript Errors Try Catch Throw