Script distance between POIs (customer sites)
This script, calculates the distance between customer sites (POIs) a vehicle is visiting, and return that distance in meters. You can see this data in a standard EV1000 report.
Requirements
To use this report, you need to have POIs set up in your application.
Setup
1. Import Script Expression - distance between POIs.xml, which contains a script expression with the scripted solution (read how to import an Event Rule for more information).
2. Modify the value My POI Category (from the script), with the POI category group name of your application.
3. Configure an EV1000 report to be used with this script.
The Script
We paste the script that is contained in the Event Rule, here as a reference.
// START OF SCRIPT // Replace 'My POI Category' with the name of the POI category where you have your customer sites. var pois = poi.find(trackPoint.position.longitude, trackPoint.position.latitude, 500, 'My POI Category') var arrived = false; if(pois.length > 0) { context.setVariable('ClientName', pois[0].name); // Arrived at customer. Set distance. context.setVariable('Distance', report.context.distance); arrived = true; } else { context.setVariable('ClientName', '-'); } // Reset distance if we just left customer site. var last = context.state; if(last != null && last.arrived == true && arrived == false) // We just left the customer, set distance to zero report.context.setDistance(0); // Remeber if we were at customer for next messgae. context.setState({arrived:arrived}); return arrived; // END OF SCRIPT
Use the EV1000 report to show the report.