My first GreaseMonkey script provides decimal degrees for cache locations. [Update: now to five decimal places.]

The cache pages at geocaching.com provide latitudes and longitudes in degrees and minutes (e.g., “N 42° 17.853”). I find that I often want to convert those coordinates into decimal degrees (e.g., “42.2975”) to plot them together on maps, to calculate distances between them, etc. I did it by hand a number of times before I discovered that the easiest way is to peek into the mapping URIs further down on the cache page.

But that's still a little bit inconvenient, and isn't this exactly what Greasemonkey is for?

Given that I've started to feel a little left out as I haven't written any fancy DHTML interfaces or jumped on the Ajax bandwagon to write the all-singing, all-dancing interactive DocBook web site, I thought that writing some Greasemonkey code would make me feel a little more relevant.

I was right. And now I have a script that adds decimal degrees to the pages in question. See?

[Photo]

Geocaching.com page with decimal degrees

Screen shot of the geocaching.com page for the Crag & Tail cache (my finding of which was prevented yesterday by the castle's closure) showing the decimal degrees added by my Greasemonkey script.

It's probably embarrassingly bad JavaScript coding, but that's what you get for a lunch break exercise at a working group meeting. Improvements accepted.

[Update 1 May 2006: Carl's right, four decimal places wasn't really enough. I've updated the script to provide five, padded with zeros if necessary.]

Comments:

installed! nice!

Posted by Paul Downey on 27 Sep 2005 @ 08:47p UTC [link]

Nice work, but a nitpick: your web server isn't saying what character set the script is in. The degree symbols are messed up in my browser.

(fortunately they're only in comments, but I said it was a nitpick!)

Posted by Brendan Taylor on 04 Oct 2005 @ 09:56p UTC [link]

Nice catch, Brendan. Fixed.

Posted by Norman Walsh on 05 Oct 2005 @ 01:03p UTC [link]

Great idea! Can you tweak the script to make it 5 decimal places rather than 4? Four decimal places (10,000ths of degrees) is grainier than DD MM.MMM format (60,000ths of degrees).

Posted by Carl on 29 Apr 2006 @ 02:34p UTC [link]

Thanks, Norman! Five digits and trailing zeroes are great additions.

Posted by Carl on 01 May 2006 @ 02:11p UTC [link]
Thanks for your script. I've changed the end of it so that it displays a link to a Google map centered on the location:
	  declatlong = "Decimal degrees: " + lat + ", " + lng + " ";
	  linkURL = "http://maps.google.com/maps?ll=" + lat
	  				+ "," + lng + "&spn=0,0";
    } else {
	  declatlong = "Decimal degrees: error, failed to match";
    }

    text = document.createTextNode(declatlong);
    br = document.createElement('br');
    if (linkURL) {
    	var link = document.createElement('a');
    	link.setAttribute("href", linkURL);
    	link.setAttribute("target", "_blank");
    	var linkText = document.createTextNode("(Google Map)");
    	link.appendChild(linkText);
    	navbar.parentNode.insertBefore(link, navbar.nextSibling);
    }
    navbar.parentNode.insertBefore(text, navbar.nextSibling);
    navbar.parentNode.insertBefore(br, navbar.nextSibling);
}
Posted by Daniel Griscom on 02 Jan 2007 @ 05:21p UTC [link]

With all the updates to gc.com & Firefox, this has stopped working. Any updates planned? I loved this script! Thanks in advance.

Posted by blugill on 18 Feb 2009 @ 03:58p UTC [link]

It still seems to work for me. What page were you on where it didn't work?

Posted by Norman Walsh on 20 Feb 2009 @ 03:44a UTC [link]
Add a comment or subscribe to (existing) comments on this essay.