The community will undergo maintenance on October 16th at 10:00 PM PDT and will be unavailable for up to one hour.
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, "");
Solved! Go to Solution.
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
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;
}
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
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
Dear Polina Osipova
thank you for your comment
i solved this issue
i declared a string variable.
and result in string
when string value equal NaN i make distance 0
thanks
Glad it got resolved! Let us know if any more assistance is needed
Just a recommendation, never use just parseInt("number"), always use parseInt("number",10) - 10 corresponds to the numeral system used -, otherwise it can parse your numbers to Octal base system or others.
Thnak you Carles Coll . i'll change parseInt(value,10)
Thank you~