Getting distance at each interval

This is how I modified your code to get the distance at each interval and sending it to a custom function to display markers at certain distances. However, I'm not sure this is a clean solution. Some sort of event/callback function would be nice.