I am currently developing a Google Maps feature in a Rails 3.2.12 project. My goal is to update the Latitude and Longitude values through the infoWindow for the location created.
When a user clicks on a marker on the map, an infoWindow will open displaying the location name along with two buttons ("Update" & "Remove"). Upon clicking on the "Update" button, the current infoWindow should close and a new infoWindow should open with latitude and longitude values displayed in text fields.
Please see my code snippet below:
When the "Update" button is clicked, the following function should be called:
function getLocation(){
currentProjectId = $('#currentProjectId').val();
sessionId = $('#sessionId').val();
userId = $('#userId').val();
var locData = {
userId: userId,
sessionId: sessionId,
command: 'locationUpdate',
projectId: currentProjectId
};
markersArray.push(marker);
currentMarker = marker;
var infoWindow = new google.maps.InfoWindow();
google.maps.event.addListener(marker, 'click', function(event){
infoWindow.close();
infoWindow.setContent("<p>Location Name: <input id="country" type="text" value='+ address +'></p>\
<p>Longitude: <input id="lat" type="text" value='+ latitude +'> </p>\
<p>Latitude: <input id="long" type="text" value='+ longitude +'> </p>\
<p><input type="button" value="Save" onclick="saveLocation(currentProjectId)"/
<input type="button" value="Remove" onclick="removeMarker()"/></p>");
infoWindow.open(map, marker);
});
currentMarker = marker;
var marker = new google.maps.Marker({
map: Gmaps.map.map,
position: new google.maps.LatLng(latitude, longitude),
draggable: true
});