Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2024 11:30 PM
Hi Everyone, I have created a string field on incident table. I have lat long of location & assigned_to. How can I calculate ETA using Google Maps API.? Please help.
Solved! Go to Solution.
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2024 11:37 PM
You need to have API keys for this. You can create BR with following script-
(function executeRule(current, previous /*previous*/) {
// Call Google Maps Directions API to get route information
var directionsURL = "https://maps.googleapis.com/maps/api/directions/json" +
"?origin=" + current.assigned_to.latitude + "," + current..assigned_to.longitude +
"&destination=" + current.location.latitude + "," + current.location.longitude +
"&key=ENTER API KEY";
var response = new sn_ws.RESTMessageV2();
response.setEndpoint(directionsURL);
response.setHttpMethod("get");
var responseBody = response.execute().getBody();
var parsedResponse = new global.JSON().decode(responseBody);
if (parsedResponse && parsedResponse.routes && parsedResponse.routes.length > 0) {
var route = parsedResponse.routes[0];
if (route && route.legs && route.legs.length > 0) {
var leg = route.legs[0];
var etaSeconds = leg.duration.value; // Duration in seconds
var etaMinutes = Math.round(etaSeconds / 60); // Convert to minutes
current.u_eta = etaMinutes; // Store ETA in the u_eta field
current.update(); // Update the record
}
}
})(current, previous);
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2024 11:37 PM
You need to have API keys for this. You can create BR with following script-
(function executeRule(current, previous /*previous*/) {
// Call Google Maps Directions API to get route information
var directionsURL = "https://maps.googleapis.com/maps/api/directions/json" +
"?origin=" + current.assigned_to.latitude + "," + current..assigned_to.longitude +
"&destination=" + current.location.latitude + "," + current.location.longitude +
"&key=ENTER API KEY";
var response = new sn_ws.RESTMessageV2();
response.setEndpoint(directionsURL);
response.setHttpMethod("get");
var responseBody = response.execute().getBody();
var parsedResponse = new global.JSON().decode(responseBody);
if (parsedResponse && parsedResponse.routes && parsedResponse.routes.length > 0) {
var route = parsedResponse.routes[0];
if (route && route.legs && route.legs.length > 0) {
var leg = route.legs[0];
var etaSeconds = leg.duration.value; // Duration in seconds
var etaMinutes = Math.round(etaSeconds / 60); // Convert to minutes
current.u_eta = etaMinutes; // Store ETA in the u_eta field
current.update(); // Update the record
}
}
})(current, previous);
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2024 11:39 PM
Spot on! Thank you so much Sir!