How to get reports from a Routing Instance in Trimble Maps JavaScript Maps SDK?

470 Views Asked by At

I would like to get mileage data using Trimble Maps Routing. The getReports() method in a Routing instance should provide this information. However, anytime i call this method i receive null. How can i get mile reports from either TrimbleMaps.Map or TrimbleMaps.Route instances?

documentation: https://developer.trimblemaps.com/maps-sdk/api/#route

<!DOCTYPE html>
<html>
<head>
  <title></title>
  <link href="https://maps-sdk.trimblemaps.com/v2/trimblemaps-2.1.1.css" rel="stylesheet">
</head>
<body>

<div id="map" style="height: 600px; width: 800px;"></div>

<script src="https://maps-sdk.trimblemaps.com/v2/trimblemaps-2.1.1.js"></script>
<script>

  TrimbleMaps.APIKey = "17CA0885B03A6B4FADBDC3D1A51DC0BD";

  let map = new TrimbleMaps.Map({
    container: "map",
    center: new TrimbleMaps.LngLat(-80.1709, 25.7745),
    zoom: 10
  });

  map.on('load', () => {
    let myRoute = new TrimbleMaps.Route({
      routeId: 'myRoute',
      stops: [
        new TrimbleMaps.LngLat(-80.35564219999999, 25.7632547),
        new TrimbleMaps.LngLat(-80.20527899999999, 25.8180518)
      ],
      reportType: [TrimbleMaps.Common.ReportType.MILEAGE]
    });
    myRoute.addTo(map);
    console.log(myRoute.getReports()); // undefined
  });

</script>

</body>
</html>
2

There are 2 best solutions below

0
Charles Xavier On BEST ANSWER

For the javascript API Trimble Maps.

myRoute.getReports() function has a listener do the following:

const myRoute = new TrimbleMaps.Route({
  routeId: "myRoute",
  stops: [
      new TrimbleMaps.LngLat(-74.566234, 40.49944),
      new TrimbleMaps.LngLat(-74.629749, 40.26118)
    ],
    reportType: [
      TrimbleMaps.Common.ReportType.MILEAGE,
      TrimbleMaps.Common.ReportType.DETAIL
    ]
  });


  // *** THIS IS THE LISTENER ****
  myRoute.on("report", function (reports) {
    console.log(reports);
  });

Reference: https://developer.trimblemaps.com/maps-sdk/guide/routing/

2
Jason Pereira On

Trimble MAPS does offer Routing Reports via the Maps Javascript platform as well as the Web Services API. The code sample you have referenced is functional but requires a Trimble MAPS API Key that includes Javascript functionality.

As for Web Services API Reporting, that documentation is located here:

REST: https://developer.trimblemaps.com/restful-apis/routing/route-reports/ SOAP: https://developer.trimblemaps.com/soap-apis/docs/reports/get-reports/

Here is an examples of a REST Mileage Report: https://pcmiler.alk.com/apis/rest/v1.0/Service.svc/route/routeReports?stops=-87.959895,42.030182;-87.572483,41.673633&reports=Mileage&dataVersion=Current&authToken=INSERT API KEY