Api api/position/get returned uncorrect positions with from, to params

chuxuanhy9 years ago

Hello,

I compiled Traccar server from git and test the api api/position/get with from and to as input params. The reponse returned positions not in the specified interval. Please check this issue!

error
Anton Tananaev9 years ago

What database are you using?

chuxuanhy9 years ago

I am using H2 - default database of Traccar. Do I need to config something else?

Anton Tananaev9 years ago

I have just double-checked and it works fine for me. I guess I need access to you web interface to check what's wrong.

chuxuanhy9 years ago

Login and account : tracking.proship.vn/api/login?password=123456&email=ngocsen.proship@gmail.com
Web interface : tracking.proship.vn

The selected from-to-data returned in the web interface was accuracy, but api didn't.

http://tracking.proship.vn/api/position/get?deviceId=4&from=2015-11-5T2:0:0.000Z&to=2015-11-5T10:0:0.000Z

Response data returned +7 hours as compared to from and to input params. For the above query :

{
    {
      "fixTime": "2015-11-05T09:00:01.000+07:00",
      "latitude": 10.799515000000001,
      "longitude": 106.73320833333334,
      "valid": true,
      "altitude": 2.2,
      "speed": 14.982081195631027,
      "course": 110.91000366210938,
      "serverTime": "2015-11-05T09:17:23.248+07:00",
      "deviceTime": "2015-11-05T09:00:01.000+07:00",
      "id": 454690,
      "protocol": "osmand",
      "attributes": {},
      "deviceId": 4
    },
    {
      "fixTime": "2015-11-05T09:00:33.000+07:00",
      "latitude": 10.798141666666668,
      "longitude": 106.73154000000001,
      "valid": true,
      "altitude": 0.1,
      "speed": 11.861397722946167,
      "course": 239.13999938964844,
      "serverTime": "2015-11-05T09:17:23.687+07:00",
      "deviceTime": "2015-11-05T09:00:33.000+07:00",
      "id": 454692,
      "protocol": "osmand",
      "attributes": {},
      "deviceId": 4
    },
...
}

database config :

<entry key='database.driver'>org.h2.Driver</entry>
<entry key='database.url'>jdbc:h2:/opt/traccar/data/database?allowMultiQueries=true&autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8</entry>
<entry key='database.user'>sa</entry>
<entry key='database.password'></entry>
<entry key='database.checkTable'>traccar</entry>
Anton Tananaev9 years ago

It looks like there is some problem. Can you send me the database file for investigation? My email address is at the bottom of the page or on the support page.

Also, what is your server's time zone?

chuxuanhy9 years ago

I have sent you an email, it is from trungtran360@gmail.com. My server time zome is set to (UTC+07:00) Bangkok, Hanoi, Jakarta.

Anton Tananaev9 years ago

I just noticed that it returns correct data. It just includes the timezone information (see +07:00 at the end).

chuxuanhy9 years ago

Yes, hope you to find out the issue soon, please give me some info then, I will fix and compile the source on my own.

Thank for your help! Have a nice weekend.

Anton Tananaev9 years ago

There are no issues as far as I can tell.

chuxuanhy9 years ago

I would like to know that how difference the bottom panel of web interface consumes the API with params. Positions return accuracy between from and to date. How params pass to the API in the web interface?

Anton Tananaev9 years ago

If you are talking about "from" and "to" parameters, they should be in ISO 8601 format.

chuxuanhy9 years ago

Hello,

After researching to find out why the web interface returned correct data with "from, to" params but consuming API in Postman did not, I meet this situation :

I added a line of code to print the from, to value sent to API in reportController.js as following :

var to = new Date( toDate.getFullYear(), toDate.getMonth(), toDate.getDate(), toTime.getHours(), toTime.getMinutes(), toTime.getSeconds(), toTime.getMilliseconds());
    console.log(from.toISOString()+" - "+to.toISOString());
    var store = Ext.getStore('Positions');

Start time was 8:00 AM, End time was 11:55 AM, and the result returned correct in that interval. But in the console the time was "2015-11-05T01:00:00.000Z - 2015-11-05T04:55:05.000Z"

I attached a screenshot, could you tell me about this situation? why did it happend?
error

Anton Tananaev9 years ago

Everything still seems fine to me. Can you please explain what's wrong on the screenshot.

chuxuanhy9 years ago

Start - end time chosen in the web interface were 8:00 AM - 11:55 AM, but the time printed by console were 1:00 AM - 4:55 AM. Time was automatically decrease by 7 hours before passed to API, instead of passed 8:00 AM - 11:55 AM to API, how did it occur?