How TrainSpeedTest.net Measures Train Speed
Three interconnected systems combine to deliver a real-time speed reading: the browser Geolocation API, mathematical formulas, and a filtering layer that removes GPS noise.
TrainSpeedTest.net reads GPS position and Doppler velocity from your device's Geolocation API, converts it to speed using the Haversine formula when needed, then smooths the result with an exponential moving average filter before displaying it.
- Native Doppler speed is used when your device reports it
- Haversine formula calculates distance between GPS points as a fallback
- EMA smoothing removes noise without hiding real acceleration
- Everything runs client-side — no GPS data is ever uploaded
Sampling rate
Continuous GPS polling
Accuracy threshold
Worse samples discarded
Stationary cutoff
1.8 km/h, treated as zero
Server transmission
Fully client-side
Three Steps From Satellite to Screen
Every reading you see passes through three stages: raw position/velocity data comes in from the Geolocation API, a calculation step turns that into a speed value, and a filtering layer smooths the result before it reaches the display. The next sections walk through each stage in detail.
The Geolocation API
When you click "Start Trip," TrainSpeedTest.net calls navigator.geolocation.watchPosition() — a browser standard that requests continuous position updates from your device's GPS hardware.
Native Doppler Speed
Many modern devices report coords.speed — a velocity derived from the Doppler shift of GPS satellite signals. When this value is available and plausible (non-negative, under 120 m/s), TrainSpeedTest.net uses it directly, as it tends to be more accurate than position-based calculation.
Haversine Position-Based Speed
When native speed is unavailable, TrainSpeedTest.net calculates speed from consecutive position samples using the Haversine formula — it accounts for Earth's curvature, which is essential for accurate results at high speed over meaningful distances.
- 1. Calculate great-circle distance between two GPS positions
- 2. Divide by elapsed time between samples
- 3. Result is speed in metres per second
Filtering and Smoothing
Raw GPS data contains noise — especially in urban environments with signal reflections, in tunnels, or when the device switches between satellite constellations. Five filters run on every incoming sample.
Accuracy Rejection
GPS samples with accuracy worse than 200 metres are discarded entirely.
Acceleration Limiting
Speed changes implying physically impossible acceleration are dampened using a weighted blend.
Exponential Moving Average
Smooths the speed signal while preserving genuine acceleration events.
Stationary Threshold
Speeds below 0.5 m/s (1.8 km/h) are treated as zero to prevent GPS drift from appearing as movement.
One Canonical Unit, Zero Rounding Drift
All speed calculations use metres per second (the SI base unit) internally. Display conversions are applied only at render time, so switching units mid-trip never introduces rounding errors into the accumulated statistics.
km/h
× 3.6
mph
× 2.23694
knots
× 1.94384
m/s
canonical
What This System Can't Do
GPS does not work in tunnels — speed readings pause until signal resumes
Urban canyons and tree cover reduce accuracy
Results are estimates, not official railway telemetry
Low speeds (below ~10 km/h) have proportionally larger uncertainty
Frequently Asked Questions
Related Train Speed Resources
See This Pipeline in Action
Open the speed test and watch your real-time reading come from exactly this process.
Works on iPhone, Android & any modern browser · Always free