Measuring speed/distance of model train set

AWOL:
A small magnet glued to the underside of the loco, and some Hall effect switches in the track?

If the position knowledge needs to be on the train then that may need to be reversed.

...R