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

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:47pm UTC #

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:56pm UTC #

Nice catch, Brendan. Fixed.

Posted by Norman Walsh on 05 Oct 2005 @ 01:03pm UTC #

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:34pm UTC #

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

Posted by Carl on 01 May 2006 @ 02:11pm UTC #
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:21pm UTC #

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:58pm UTC #

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:44am UTC #
Add a comment or subscribe to (existing and future) comments on this essay.
Name:
Email*:
 *Please provide your real email address; it will not be displayed as part of the comment.
Homepage:
Comment**:
 **The following markup may be used in the body of the comment: a, abbr, b, br, code, em, i, p, pre, strong, and var. You can also use character entities. Any other markup will be discarded, including all attributes (except href on a). Your tag soup will be sanitized...