HomeCoding & Programming

Google Maps: Easy Way to Find Latitude and Longitude Values of a Place in Google Maps

Like Tweet Pin it Share Share Email

If you are playing with Google Maps, and want to get Latitude and Longitude of any location on Earth no worries.
Follow below few simple steps to go.

<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=GOOGLE_MAP_KEY"></script>
 
<div class="Mapblock">
<div style="height:auto;">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<div id="map" align="center" style="height: 276px;width:276px;border: 1px solid #DDDDDD; font-size:12px; font-weight:normal; color:#000000;"></div>

<script type="text/javascript">

if( window.addEventListener )
	window.addEventListener( 'load', load, false );
else
	window.attachEvent( 'onload', load );

	function load() {
	
		//<![CDATA[
		var map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		
		map.setCenter(new GLatLng(27.137368,75.761718), 5);
		var marker = new GMarker(new GLatLng(37.4419, -122.1419), {draggable: true});
		map.addOverlay(marker);
		
		GEvent.addListener(map, 'click', function(overlay, point) {
		if(point)
		{
			var lati=point.lat(); //alert(lati);
			var long=point.lng(); //alert(lati);
			var marker= new GMarker(new GLatLng(lati, long),{draggable: true});
			map.addOverlay(marker);
			marker.openInfoWindowHtml("Latitude&nbsp;&nbsp;&nbsp;"+lati+"<br>"+"Longitude&nbsp;&nbsp;&nbsp;"+long);
			
			GEvent.addListener(marker, "dragend", function() {
				var point = marker.getPoint();
				var lati=point.lat();
				var long=point.lng();
				marker.openInfoWindowHtml("Latitude&nbsp;&nbsp;&nbsp;"+lati+"<br>"+"Longitude&nbsp;&nbsp;&nbsp;"+long);
			});
		}
		});
		
		GEvent.addListener(map, 'singlerightclick', function(point,src,overlay)
		{
			if(overlay){
				if(overlay != marker) { map.removeOverlay(overlay) }
			}
		}
		);
		//]]>
	
	}
</script>
</div>
</div>

 

 

  1. Get google map key.You can get from the below link of Google Map.Here I am using version2,in version3 of google map,we don’t need key.
  2. Replace GOOGLE_MAP_KEY with your google map key.
  3. Copy and paste the script in your code.
  4. Set the center of the map (Default center) by replacing the respective Latitude and Longitude.
map.setCenter(new GLatLng(27.137368,75.761718), 5);

 

Here number 5 is zoom level,you can set this one also.

 

  1. Run the code.
  2. Click on any point on the map,a popup will automatically show up with the respective Latitude and Longitude(co-ordinates) of that point.
  3. If you want to discard it,don’t worry,just right click on the google map marker.

 

Comments (3)

  • Hey there! I’ve been following your site for some time now and finally got the bravery to go ahead and give you a shout out from Atascocita Tx! Just wanted to mention keep up the excellent job!

  • Hi there! This article could not be written any better!
    Reading through this article reminds me of my previous roommate!
    He always kept preaching about this. I’ll send this post to him. Fairly certain he’ll have a good read.
    I appreciate you for sharing!

  • Howdy! I simply want to give you a big thumbs up for the great info you have got here on this
    post. I’ll be returning to your website for more soon.

Comments are closed.