Skip to content

Instantly share code, notes, and snippets.

@pokutuna
Created January 6, 2013 07:52
Show Gist options
  • Save pokutuna/4465923 to your computer and use it in GitHub Desktop.
Save pokutuna/4465923 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
class Util
def self.deg2rad(degree)
degree * Math::PI / 180.0
end
# ヒュベニの距離計算式 単位: m
def self.geo_distance(geo_a, geo_b)
lat_ave = deg2rad((geo_a[:lat] + geo_b[:lat]) / 2.0)
lat_diff = deg2rad(geo_a[:lat] - geo_b[:lat])
lon_diff = deg2rad(geo_a[:lon] - geo_b[:lon])
m = 6335439.327 / Math.sqrt((1.0 - 0.00669438 * Math.sin(lat_ave) ** 2) ** 3)
n = 6378137.0 / Math.sqrt(1.0 - 0.00669438 * Math.sin(lat_ave) * 2)
Math.sqrt((m * lat_diff) ** 2 + (n * Math.cos(lat_ave) * lon_diff) ** 2)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment