Skip to content

Instantly share code, notes, and snippets.

@jeena
Created November 27, 2012 13:34
Show Gist options
  • Save jeena/4154241 to your computer and use it in GitHub Desktop.
Save jeena/4154241 to your computer and use it in GitHub Desktop.
function degrees2dezimal(a) {
var a, h=0, m=0, s=0;
a = a.split("°");
h = parseInt(a[0].replace(/N|S|O|W/, ""), 10);
h = isNaN(h) ? 0 : h;
if (a.length > 1) {
a = a[1].split("'");
m = parseInt(a[0], 10);
m = isNaN(m) ? 0 : m / 60;
if (a.length > 1) {
a = a[1].split('"');
s = parseInt(a[0], 10);
s = isNaN(s) ? 0 : s / 3600;
}
}
return h + m + s;
}
if (typeof process != "undefined" && typeof process.argv[2] == "undefined") {
console.log("usage: node " + process.argv[1] + " \"102°03'W\"")
} else if(typeof process != "undefined" && typeof process.argv[2] == "string") {
console.log(degrees2dezimal(process.argv[2]));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment