Sorry, the "Distance" vs "distance" was a typo (I had a local test I played with, to get the values right - before using it on the live site , which used ->{Distance} and not ->{distance})
Your code worked a charm, thanks! I'll have to remember that for the future, as I'm sure I will need similar code at some point