Google Maps Show Coords

By JRI Last update Dec 11, 2011 — Installed 2,346 times.

Proposed review

in
Subscribe to Proposed review 2 posts, 2 voices



JSO User
FirefoxX11

Hi JRI

First of, thanks for conrtibuting this very useful script.

I installed it a few minutes ago and realized that for some reason it wouldn't work after searching for an address.

I tweaked it a little and added a little textarea next to the link to make it easier to copy/paste the resulting coordinates. This is what I propose:

#############

// ==UserScript==
// @name Google Maps Show Coords Link
// @namespace http://inge.org.uk/userscripts
// @description Creates a link on Google Maps to show the map centre coordinates.
// @include http://maps.google.tld/*
// @include http://www.google.tld/local*
// @include http://www.google.tld/maps*
// @license MIT License; http://www.opensource.org/licenses/mit-license.php
// ==/UserScript==

(function() {
function addGeoLink() {
var targets = document.evaluate("//div[@id='topbar-endcol']/div[@class='end-edge-links']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
if (targets.snapshotLength == 1) {
targets.snapshotItem(0).innerHTML +=
"?
}
}

addGeoLink();
})();

#############

Cheers,
JSO

 
JRI Script's Author
Firefox

Hi JSO,

I'm glad you found the script useful.

I've had a look at the code and found a more elegant way to get hold of the map coordinates. That solved the bug you mentioned, which sometimes stopped the script working until you adjusted the map. It will also shave a couple of processor cycles off the execution time!

At the same time, I tried to make the coordinates update automatically, by adding an event listener that watches to see when the map is moved. Unfortunately that didn't work. It seems that the code on Google's own map page doesn't use quite the same functions as they make available in the API for putting maps on your own web pages. If anyone knows how to make it work, let me know!

It looks like the USO website has mangled the code your comment, so I'm not sure where you were going with adding a textarea to the script. However, I like to make sure that the text added by the script fits the style of the rest of the page and doesn't take up too much space. Because of this, I've implemented a copy-to-clipboard function instead.

Now, once you've got some coordinates showing, you can right-click on them to copy them to the clipboard. To make this work in Firefox, you have to set the 'signed.applets.codebase_principal_support' preference to 'true' in about:config, then agree to a security prompt when you first use the function. If this feature is working, you won't see anything happen when you right-click (other than the security prompt). If it isn't, then the standard context menu will pop up, and you can cut'n'paste as normal.

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel