I have a form, which is submmited via the malsup ajaxForm plug-in, and I want the ajax call to wait until leaflet accurate position plug-in finds an accurate position, so then I can append it to the data sent by the form setting it in some hidden fields I have in my html. The thing is, I don't really have a clear way of how to do this.
I have the following:
function InitMap()
{
map = L.map('map');
function onAccuratePositionError (e) {
addStatus(e.message, 'error');
}
function onAccuratePositionProgress (e) {
}
function onAccuratePositionFound (e) {
$('#latitud').val(e.latlng.lat);
$('#longitud').val(e.latlng.lng);
$('#presicion').val(e.accuracy);
}
map.on('accuratepositionprogress', onAccuratePositionProgress);
map.on('accuratepositionfound', onAccuratePositionFound);
map.on('accuratepositionerror', onAccuratePositionError);
}
And my Ajax call:
function InitJForm()
{
$('form').ajaxForm({
beforeSubmit:Geolocalizar,
success: function(datos)
{
window.location.href = 'some url...';
},
error: function(datos)
{
var w = window.open('about:blank');
w.document.open();
w.document.write(datos.responseText);
w.document.close();
}
});
}
The geolocation call:
function Geolocalizar()
{
map.findAccuratePosition({
maxWait: 15000,
desiredAccuracy: 20
});
return true;
}
Is there a way to make the geolocation call to wait for the findaccurateposition function to finish finding the location before sending a true and submitting the request?