Google Maps Latitude and Longitude

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?

Le Update 1

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));

8 Responses to “Google Maps Latitude and Longitude”


  1. 1 Roger 2008-02-12 at 09:03:38

    Almost exactly what I wanted! :-)
    The ideal would be to have the output string from your one line in a format that could be pasted back into Google maps at some point in the future or by a third party. Such as 00 00 00N 0 00 00W
    Thanks for your hard work.

  2. 2 ThomasV 2008-03-23 at 15:27:16

    If you want to import in MapSource

    oneline:
    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*coord[x]; output += (x==0?(neg?’S':’N'):(neg?’W':’E')) + coord[x] + ‘ ‘; }; void(prompt(”, output));

    ThomasV from Slovenia.

  3. 3 ThomasV 2008-03-23 at 15:32:21

    Again, some strnge copy paste… grrr, here we go again:

    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*coord[x]; output += (x==0?(neg?’S':’N'):(neg?’W':’E')) + coord[x] + ‘ ‘; }; void(prompt(”, output));

  4. 4 ThomasV 2008-03-23 at 15:34:50

    Ok this web page convert ‘ ‘ to ” !

    It should be
    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*coord[x]; output += (x==0?(neg?’S':’N'):(neg?’W':’E')) + coord[x] + ‘ ‘; }; void(prompt(‘ ‘, output));

    Hope now it will be OK.

  5. 5 ThomasV 2008-03-23 at 15:40:41

    It is not OK :( , so change it manually after copy paste …

    It should be always character ‘
    as it is in first post!

  6. 6 Santhosh 2009-06-15 at 07:06:08

    Is there a way to find the location, if I know the coordinates?


  1. 1 Address Book to Google Maps to RouteBuddy at bioneural.net Trackback on 2008-07-17 at 14:46:51
  2. 2 Getting longtitude and latitude coordinates from the centre of a google map « An Cuasán Trackback on 2009-08-20 at 20:15:06

Leave a Reply




 

June 2007
M T W T F S S
« May   Jul »
 123
45678910
11121314151617
18192021222324
252627282930  

a

Reverse

To reverse the order of the entries (chronogical top-to-bottom), paste this into your address bar, and hit Enter: