Skip to content

Instantly share code, notes, and snippets.

@iaindooley
Created April 29, 2019 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iaindooley/147c8894b9423dcd3cd21e3039fd347f to your computer and use it in GitHub Desktop.
Save iaindooley/147c8894b9423dcd3cd21e3039fd347f to your computer and use it in GitHub Desktop.
Get next closest location
function getNextClosestLocation(notification)
{
var notif = new Notification(notification);
//trigger when a due date marked complete
var card = notif.completedDueDate();
//build an array of distances between this card and all
//other cards on the board
var distances = [];
card.board().cards().each(function(loop)
{
distances.push({dist: getDistanceBetweenLocationsFromGoogleMapsApi(card.customFieldValue("Address"),
loop.customFieldValue("Address")),
card: loop}
);
});
distances.sort(function(a,b)
{
return a.dist - b.dist;
});
if(distances.length)
notif.replyToMember("Your next delivery is: "+distances[0].card.link());
}
function getDistanceBetweenLocationsFromGoogleMapsApi(address1,address2)
{
//do this using the maps directions API:
//https://stackoverflow.com/questions/4174642/google-apps-script-map-api-for-distance-calculation-between-two-points
return distance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment