\
Ruby

Compute the Distance Between Two Latitude/Longitudes - Haversine Formula in Ruby

Synopsis: Haversine formula in Ruby. This is Ruby code to compute the distance between two points when their position is given as a latitude and longitude. It’s very handy and I used it to compute an absolute distance to signal strength graph using a GPS and custom code I wrote which could read signal strength from a embedded WiFi device I was testing. The test was undertaken to determine the signal strength vs distance characteristics in the field of a LANtronix Matchport b/g. This article answers the question: How to compute the distance between two GPS coordinates using Ruby?

Here’s one of many resulting graphs (gnuplot) based on lat/lon points, ping latency, and signal strength. There were many more graphs and tests done, but this gives you an idea of what the Haversine formula is good for. For every lat/lon I took a signal strength reading (automated of course.) Using the Haversine formula coded in Ruby, presented below, I could easily compute the distance between points to create a signal strength to distance graph. Those distances comprised the X axis of this graph of Signal Strength and Ping latency vs Distance in feet:

LANtronix Matchport b/g signal strength

asdfasdf