Skip to content

Instantly share code, notes, and snippets.

@samg
Last active December 30, 2015 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samg/7783319 to your computer and use it in GitHub Desktop.
Save samg/7783319 to your computer and use it in GitHub Desktop.
module Earth
extend self
def meters_between_two_points(p1, p2)
( 6378.0 * Math.acos([
Math.cos(p1.lat_in_radians) * Math.cos(p2.lat_in_radians) *
Math.cos(p2.lng_in_radians - p1.lng_in_radians) +
Math.sin(p1.lat_in_radians) * Math.sin(p2.lat_in_radians),
1
].min)) * 1000
end
end
# meters = Earth.meters_between_two_points(p1,p2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment