This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
St. James's Park: 51.49954,-0.13358 | |
Trafalgar Square: 51.508039,-0.128069 | |
Buckingham Palace: 51.501364,-0.14189 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |