function playgroundsNew(geocode_information) { // Create an new marker playgroundsNewMarker = new google.maps.Marker({ position: new google.maps.LatLng(geocode_information.latitude,geocode_information.longitude), map: Gmaps.map.serviceObject, icon: 'http://www.google.com/mapfiles/marker_green.png', }); // Invoke rails app to get the create form $.ajax({ url: '/playgrounds/new?' + jQuery.param({playground:geocode_information}) + '#chunked=true', type: 'GET', async: false, success: function(html) { // Add on close behaviour to clear this marker var createFormOpen = function() { // Open new form openInfowindow(html, playgroundsNewMarker); // Add close infowindow behaviour google.maps.event.addListener(Gmaps.map.visibleInfoWindow,'closeclick', function(){ clearMarker(playgroundsNewMarker); }); } // Invoke now createFormOpen(); // Clicking "again" on the new marker will reproduce behaviour google.maps.event.addListener(playgroundsNewMarker, "click", function() { createFormOpen(); }); } }); }