Created
April 29, 2019 23:28
-
-
Save iaindooley/147c8894b9423dcd3cd21e3039fd347f to your computer and use it in GitHub Desktop.
Get next closest location
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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