I am working on google Maps API. I dont know why the below function is being called after the index++. As far as I know ReverseGeocode() should be called first. Instead of that it is first incrementing and then calling the function which is creating problems for me. The alert boxes are shown as they are written but the middle function is called after the last line of the function is executed i.e (index++).
function placeMarker(location)
{
alert("iiii");
ReverseGeocode(location.lat(),location.lng());
alert("jjjk");
index++;
}
Here is my ReverseGeoCode
function ReverseGeocode(lat,lng) {
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({'latLng': latlng}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
if (results[1])
{
places[index]=results[0].formatted_address;
alert(places[index]+"index="+index);
AddRow('table',results[0].formatted_address);
document.getElementById("dataa").innerHTML+=results[0].formatted_address+"<br/>";
}
}
else
{
alert("Geocoder failed due to: " + status);
}
});
}
Please Explain. Thanks in advance.
ReverseGeoCodeexecutes afterindex++?geocoder.geocodeasynchronous?GeoCodefunction and execute it at the end of the function; then you can pass any dependent operations such as yourindexincrement into the callback.