I have a Google Map V3 map. When a user clicks on it an confirmation alert popup asking them if they want to add the marker there. If they say yes then marker is added. Code is as below;
EDIT: Standard JS working version on JSFiddle:
http://jsfiddle.net/sT8xU/4/
google.maps.event.addListener(map, 'click', function (event) {
if (event.latLng) {
var answer = confirm("Add marker?");
if (answer) {
addMarker(map, event.latLng);
}
}
});
This works fine. I have now tried to convert this standard alert to a JQuery dialog as below; but not able to get it work. What I would like is for the addMarker function to be called with the map and event parameters as above from the JQuery UI dialog.
Trying to get this working on JSFiddle
http://jsfiddle.net/sT8xU/5/
google.maps.event.addListener(map, 'click', function (event) {
if (event.latLng) {
$('#divConfirmDialog').html('Add marker?'); $('#divConfirmDialog').dialog('open');
function showResultsTest(x) {
addMarker(map, event.latLng);
alert(x);
}
}
});
$('#divConfirmDialog').dialog({
buttons: {
"Add": function () {
x = "1";
$(this).dialog("close");
showResultsTest(x);
},
"Don't add": function () {
$(this).dialog("close");
}
}
});
Thanks
Here you go: http://jsfiddle.net/sT8xU/9/
I added
var eventlatLng;under your global declaration of themapvar. I then set that in thegoogle.maps.event.addListenerfunction. ThenaddMarker(map, eventlatLng);is called in theAdd Markerbutton function.