Nov 19, 2013, by admin
If you are playing with google map, and want to get Latitude and Longitude of any location.
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 ”+lati+”<br>”+”Longitude ”+long);
GEvent.addListener(marker, “dragend”, function() {
var point = marker.getPoint();
var lati=point.lat();
var long=point.lng();
marker.openInfoWindowHtml(“Latitude ”+lati+”<br>”+”Longitude ”+long);
});
}
});
GEvent.addListener(map, ‘singlerightclick’, function(point,src,overlay)
{
if(overlay){
if(overlay != marker) { map.removeOverlay(overlay) }
}
}
);
//]]>
}
</script>
</div>
</div>
map.setCenter(new GLatLng(27.137368,75.761718), 5);
Here number 5 is zoom level,you can set this one also.