Wednesday, June 23, 2010

A simple program to show location on a HTML page using Google Map

For this you must be connected to internet.

1. Open a text file and store it on your desktop.
2. Name it as test.html
3. Open the file in edit mode using a notepad.

copy paste the following code

<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(25.15, 86.35);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}

</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>

In the above code ,replace 25.15 with latitude of your place and 86.25 with longitude of your place in new google.maps.LatLng(25.15, 86.35)

You can find longitude and latitude of your place using this side.
http://www.earthtools.org/ 
There are many other similar sites.

Now save the file. Open test.html using a web browser like IE or Firefox. You will see Google map pointing to that location.

No comments:

Post a Comment