Created
March 18, 2013 18:43
-
-
Save iwek/5189674 to your computer and use it in GitHub Desktop.
JavaScript Geographic Coordinate Conversion
This file contains hidden or 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
function convert(geo){ | |
var latlonrg = /(\d+(?:\.\d+)?)[\xb0\s]?\s*(?:(\d+(?:\.\d+)?)['\u2019\u2032\s])?\s*(?:(\d+(?:\.\d+)?)["\u201d\u2033\s])?\s*([SNEW])?/i; | |
var m = String(geo).split(latlonrg), | |
lat = m && +m[1] + (m[2] || 0) / 60 + (m[3] || 0) / 3600; | |
if (m[4].toUpperCase() == "S") { | |
lat = -lat; | |
} | |
var lon = m && +m[6] + (m[7] || 0) / 60 + (m[8] || 0) / 3600; | |
if (m[9].toUpperCase() == "W") { | |
lon = -lon; | |
} | |
return lat+','+lon; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment