Get lattitude and longitude onmouseover and onclick event in google map v3

As you move the mouse over the google map you can see the lattitude and longitude displayed below the google map.
When you click on google map the lattitude and longitude of the mouse position is displayed in the text box below the google map.
This example is very simple so you can just view the source code to copy and use it. anyway i have explained below.

Lattitude:
Longitude:
Lat Lng:
Lat Lng on click:

Code and Explanation

You can also copy this code by viewing the source code of this page
var map;
function mapa()
{
	var opts = {'center': new google.maps.LatLng(26.12295, -80.17122), 
	'zoom':11, 'mapTypeId': google.maps.MapTypeId.ROADMAP }
	map = new google.maps.Map(document.getElementById('mapdiv'),opts);
	
	google.maps.event.addListener(map,'click',function(event) {
		document.getElementById('latlongclicked').value = event.latLng.lat() + ', ' + event.latLng.lng()
	})

	google.maps.event.addListener(map,'mousemove',function(event) {
		document.getElementById('latspan').innerHTML = event.latLng.lat()
		document.getElementById('lngspan').innerHTML = event.latLng.lng()
		document.getElementById('latlong').innerHTML = event.latLng.lat() + ', ' + event.latLng.lng()
	});	
}

That is all folks. Enjoy.

By -

Comments, Suggestions, Objections, ...