views:

27

answers:

1

Hey Guys,

I'm new to Google maps and I'm wondering how would I program a Map which would pop out a HTML form when the user clicked a location on the map? I'd like the form to "pop out" of the map on screen. is this possible?

I've got the following...

         <script>
        var contentString = '<div id="content">
       <form action="welcome.php" method="post">
       <b>Name</b><br/> <input type="text" name="fname" />
       <br/><b>Description</b><br/>
       <TEXTAREA NAME="description" COLS=40 ROWS=6></TEXTAREA><br/><br/>
       <b>Latitude</b><br/><INPUT name="lat" id ="lat" /><br/>
       <b>Longitude</b><br/><INPUT name="lng" id ="lng" /><br/>
       <input type="submit" />
       </form>
       </div>';

var infowindow = new google.maps.InfoWindow({ content: contentString });

My on click listener is...

GEvent.addListener(map, "click", function(overlay, latLng)
{
    if (latLng) {
 marker = new GMarker(latLng, {draggable:true});
 map.addOverlay(marker);
 infowindow.open(latLng, map);
  }

    // display the lat/lng in your form's lat/lng fields
    document.getElementById("lat").value = latLng.lat();
    document.getElementById("lng").value = latLng.lng();
});

  }
}

What I want is on click It'll open a HTML form at the location where the user clicked and pass on the lat/lng fields to the HTML form. is this possible?

+1  A: 

All the information you need is in the documentation, along with an example - all you need to do is put the HTML form in there.

nathan
Can I not have it so the form would appear if the user was to click at a point on that map which wasnt an icon?
Ulkmun
@Meowmix ummm yes, just add the eventListener to the map instead of the marker..
nathan
umm, could you explain with some code? I', really unsure what you mean. Sorry, new to Google maps API :(
Ulkmun