Form info window

         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!

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.
<script type="text/javascript" src=""></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)
function placeMarker(location)
    var marker = new google.maps.Marker(
        position: location,
        map: map

    var coords= + ',' + 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()
<body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width: 100%; height: 100%"></div>

         The output of the above code will look as seen below!

           If you have any queries regarding the above code feel free to comment here or drop me a mail. If there are any recommendations regarding content of posts, then please mail me your wish list!

Popular posts from this blog

Where does Google get it's live traffic data from?

jQuery Mobile's Next Big Step

Geodesic Polyline