Skip to content

Instantly share code, notes, and snippets.

@lunivore
lunivore / Geolocations.txt
Last active August 29, 2015 14:14
Some well-known London locations and GPS coordinates
St. James's Park: 51.49954,-0.13358
Trafalgar Square: 51.508039,-0.128069
Buckingham Palace: 51.501364,-0.14189
@lunivore
lunivore / gps_calculator.rb
Created February 5, 2015 11:38
Distance calculator for GPS coordinates
class GpsCalculator
def distance loc1, loc2
rad_per_deg = Math::PI/180 # PI / 180
rkm = 6371 # Earth radius in kilometers
rm = rkm * 1000 # Radius in meters
dlat_rad = (loc2[0]-loc1[0]) * rad_per_deg # Delta, converted to rad
dlon_rad = (loc2[1]-loc1[1]) * rad_per_deg
lat1_rad, lon1_rad = loc1.map {|i| i * rad_per_deg }