Skip to content

Instantly share code, notes, and snippets.

Created April 25, 2012 20:42
What would you like to do?
Programing Problem: Decimalize Latitude Longitude
# Decimalize latitude longitude
# "37°26′36.42″N 06°15′14.28″W" --> (37.44345 -6.253966666666667)
$regex = %r{
def decimalize_location(location)
if g = $regex.match(location)
lat = g['lat_deg'].to_i + g['lat_min'].to_f/60 + g['lat_sec'].to_f/3600
lat = -lat if g['lat_hemi'] == 'S'
lng = g['lng_deg'].to_i + g['lng_min'].to_f/60 + g['lng_sec'].to_f/3600
lng = -lng if g['lng_hemi'] == 'W'
{y:lat, x:lng}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment