Today we will look at a Google Maps API v3 example to add a form in the information bubble! This is usually required when we wish to accept some data/information from the user! This data can be saved to a server in the form of an XML file or a database! The information can then be retrieved back at a later stage, when necessary!
In this example we will only look at form in the information bubble! The connectivity part with the server will be discussed in another post! So, today's code snippet is as seen below!
<html>
<head>
<title>
Google Maps API v3 - Adding marker and info window on Click and creating a form in the infowindow with the lat-lng information in it.
</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var map; //When using event as a parameter to a function declare map, strictly as a global variable
function initialize()
{
var myLatlng = new google.maps.LatLng(28.635157,77.22496);
map = new google.maps.Map(document.getElementById("map_canvas"),
{
zoom: 14,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
google.maps.event.addListener(map, 'click', function(event)
{
placeMarker(event.latLng);
});
}
function placeMarker(location)
{
var marker = new google.maps.Marker(
{
position: location,
map: map
});
var coords= location.lat().toFixed(6) + ',' + location.lng().toFixed(6);
var html = "<table>" +
"<tr><td>Name:</td> <td><input type='text' id='name'/> </td> </tr>" +
"<tr><td>Location:</td> <td><input type='text' value = " + coords +" id='loc'></td> </tr>" +
"<tr><td>Cache Object Taken:</td> <td><input type='text' id='ctake'/></td> </tr>" +
"<tr><td>Cache Object Placed:</td> <td><input type='text' id='cput'/></td> </tr>" +
"<tr><td></td><td><input type='button' value='Save' onclick='saveData()'/></td></tr>";
var infowindow = new google.maps.InfoWindow(
{
content: html
});
google.maps.event.addListener(marker, 'click', function()
{
infowindow.open(map,marker);
});
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width: 100%; height: 100%"></div>
</body>
</html>
The output of the above code will look as seen below!
In this example we will only look at form in the information bubble! The connectivity part with the server will be discussed in another post! So, today's code snippet is as seen below!
<html>
<head>
<title>
Google Maps API v3 - Adding marker and info window on Click and creating a form in the infowindow with the lat-lng information in it.
</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var map; //When using event as a parameter to a function declare map, strictly as a global variable
function initialize()
{
var myLatlng = new google.maps.LatLng(28.635157,77.22496);
map = new google.maps.Map(document.getElementById("map_canvas"),
{
zoom: 14,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
google.maps.event.addListener(map, 'click', function(event)
{
placeMarker(event.latLng);
});
}
function placeMarker(location)
{
var marker = new google.maps.Marker(
{
position: location,
map: map
});
var coords= location.lat().toFixed(6) + ',' + location.lng().toFixed(6);
var html = "<table>" +
"<tr><td>Name:</td> <td><input type='text' id='name'/> </td> </tr>" +
"<tr><td>Location:</td> <td><input type='text' value = " + coords +" id='loc'></td> </tr>" +
"<tr><td>Cache Object Taken:</td> <td><input type='text' id='ctake'/></td> </tr>" +
"<tr><td>Cache Object Placed:</td> <td><input type='text' id='cput'/></td> </tr>" +
"<tr><td></td><td><input type='button' value='Save' onclick='saveData()'/></td></tr>";
var infowindow = new google.maps.InfoWindow(
{
content: html
});
google.maps.event.addListener(marker, 'click', function()
{
infowindow.open(map,marker);
});
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width: 100%; height: 100%"></div>
</body>
</html>
The output of the above code will look as seen below!
This comment has been removed by the author.
ReplyDeleteNice Information, I like the simplicity of your blog Shreerang. It gives out information with code. I am interested to know what other applications you have worked on?
ReplyDeleteWould you mind mentioning them on the blog?
Thanx for your appreciation Sid! I will definitely, gradually put in some of the applications that I have developed on the blog!
ReplyDeleteThank you, I appreciate it.
ReplyDeleteHello,
ReplyDeleteThanks for the information. The above information are very simple and useful.
could you please have a post on the below.?
This data can be saved to a server in the form of an XML file or a database! The information can then be retrieved back at a later stage, when necessary!
Thanks in advance for your posting
Regards
SONA