Updated
Inspired by the post from Lifehacker, which is a re-post from tech-recipes, here’s how to get Google Maps coordinates in degrees, minutes and seconds:
javascript:coord = [gApplication.getMap().getCenter().lat(),gApplication.getMap().getCenter().lng()];
output = '';
for (x in [0,1]) {
neg = (coord[x] < 0);
if (neg) coord[x] *= -1;
deg = Math.floor(coord[x]);
minr = (coord[x] - deg) * 60;
min = Math.floor(minr);
sec = Math.floor((minr - min) * 60 * 100000)/100000;
output += (x==0?'Lat':', Long') + ': ' + deg + "° " + (min < 10?'0':'') + min + "' " + (sec < 10?'0':'') + sec + '" ' + (x==0?(neg?'S':'N'):(neg?'W':'E'));
};
void(prompt('', output));
Also do-able in one line
:
javascript:coord=[gApplication.getMap().getCenter().lat(),gApplication.getMap().getCenter().lng()];output='';for(x in [0,1]){neg=(coord[x]<0);if (neg) coord[x]*=-1;deg=Math.floor(coord[x]);minr=(coord[x]-deg)*60;min=Math.floor(minr);sec=Math.floor((minr - min)*60*100000)/100000;output+=(x==0?'Lat':', Long')+': '+deg+"° "+(min<10?'0':'')+min+"' "+(sec<10?'0':'')+sec+'" '+(x==0?(neg?'S':'N'):(neg?'W':'E'));};void(prompt('',output));
How to use? Just open up Google Maps, center the view to the place you want the coordinates of and paste the one-liner into the address bar. Or make a new bookmark, paste the line into “Location”, and “open” the bookmark while you’re in Google Maps.
Yay!
Of course, the question is, use +/- notation or north/south and east/west?
Roger wanted the output to be pastable into Google Maps. Not hard actually…
Google Maps Compatible Output
javascript:coord=[gApplication.getMap().getCenter().lat(),gApplication.getMap().getCenter().lng()];output='';for(x in [0,1]){neg=(coord[x]<0);if (neg) coord[x]*=-1;deg=Math.floor(coord[x]);minr=(coord[x]-deg)*60;min=Math.floor(minr);sec=Math.floor((minr - min)*60*100000)/100000;output+=deg+"° "+(min<10?'0':'')+min+"' "+(sec<10?'0':'')+sec+'" '+(x==0?(neg?'S ':'N '):(neg?'W':'E'));};void(prompt('',output));
and ThomasV tried to comment but WordPress trying to be smart broke his quotes. I guess MapSource is a program?
MapSource Compatible Output
javascript:coord = [gApplication.getMap().getCenter().lat(),gApplication.getMap().getCenter().lng()]; output = ''; for (x in [0,1]) { neg = (coord[x] < 0); if (neg) coord[x] *= -1; output += (x==0?(neg?'S':'N'):(neg?'W':'E')) + coord[x] + ' '; }; void(prompt('', output));
Update 2009-02-08: Target Box
I updated the code, it now inserts a small semi-transparent box in the middle of the map, click on it and it will tell you the coordinates of the cent(re|er) of the map. Yay!
javascript:var tgt = document.createElement('div'); tgt.setAttribute('style', 'border: 1px solid blue; background-color: white; position: absolute; top: 49%; left: 49%; height: 2%; width: 2%; opacity: 0.5;'); tgt.onclick = function() { coord=[gApplication.getMap().getCenter().lat(),gApplication.getMap().getCenter().lng()];output='';for(x in [0,1]){neg=(coord[x]<0);if (neg) coord[x]*=-1;deg=Math.floor(coord[x]);minr=(coord[x]-deg)*60;min=Math.floor(minr);sec=Math.floor((minr - min)*60*100000)/100000;output+=(x==0?'Lat':', Long')+': '+deg+"° "+(min<10?'0':'')+min+"' "+(sec<10?'0':'')+sec+'" '+(x==0?(neg?'S':'N') : (neg?'W':'E'));};prompt('Coordinates',output); }; void(document.getElementById('map').appendChild(tgt));