გადასვლა მთავარ შინაარსზე

How do I get total distance traveled by a vehicle from a specific date / time using the MyGeotab API?

AaronD-Geotab-IICON
Geotabber
ორიგინალი ავტორი

How do I get the kilometres traveled by a vehicle since a specific date and time using the API?

 

Specifically when odometer information isn't provided by the vehicle.

 

[Question pulled from reseller email.]

ჩაერთეთ დისკუსიაში

You need to be logged in to reply to this post and participate in the Geotab Community discussions.

საუკეთესო პასუხები

AaronD-Geotab-IICON
Geotabber
ორიგინალი ავტორი

To do this, we can grab all the Trips recorded for the device in question.

 

We use the fromDate to give us a starting point, and the deviceSearch to get the vehicle we want. You could also use the toDate parameter in the Search if you didn't want all records up to the current time.

 

For this example, we will use June 1st, 2020 as our date, and I filled in a vehicle ID that I used in testing, please remember to change to your vehicle ID.

 

var wDate = "2020-06-01T00:00:00.000Z";

var wDevice = "bCF"

 

api.call("Get", {

  "typeName": "Trip",

  "search" : {

           "fromDate" : wDate,

    "deviceSearch" : { "id" : wDevice }

  },

}, function(results) {

  var totalDistance = 0;

  for(var i = 0; i < results.length; i++){

    totalDistance = totalDistance + results[i].distance;

     

  }

  console.log("Total Distance: ", totalDistance);

}, function(e) {

  console.error("Failed:", e);

});

 

 

 

 

 

 

1 პასუხი

AaronD-Geotab-IICON
Geotabber
ორიგინალი ავტორი

To do this, we can grab all the Trips recorded for the device in question.

 

We use the fromDate to give us a starting point, and the deviceSearch to get the vehicle we want. You could also use the toDate parameter in the Search if you didn't want all records up to the current time.

 

For this example, we will use June 1st, 2020 as our date, and I filled in a vehicle ID that I used in testing, please remember to change to your vehicle ID.

 

var wDate = "2020-06-01T00:00:00.000Z";

var wDevice = "bCF"

 

api.call("Get", {

  "typeName": "Trip",

  "search" : {

           "fromDate" : wDate,

    "deviceSearch" : { "id" : wDevice }

  },

}, function(results) {

  var totalDistance = 0;

  for(var i = 0; i < results.length; i++){

    totalDistance = totalDistance + results[i].distance;

     

  }

  console.log("Total Distance: ", totalDistance);

}, function(e) {

  console.error("Failed:", e);

});

 

 

 

 

 

 

კვლავ გაქვთ შეკითხვები?