My problem is this .I am new to javascript. I have a function which makes an asynchronous call to a Google map API (which returns location based on latlng) .This function in my code is MarkerCreaterPlusLocation. This call returns a value which I need in another function which is named MarkerCreater in my code. But the problem is that MarkerCreater does not stop for the MarkerCreaterPlusLocation to return the value .
To overcome this problem I tried using the callback for the MarkerCreater to get executed when the asynchronous function returns the value
The structure is as follows :
google.maps.event.addListener(map, 'click',addLatLng); //This code attaches the function to Listener
function addLatLng(event) {
path = poly.getPath();
path.push(event.latLng);
MarkerCreaterPlusLocation(event.latLng,MarkerCreater);//MarkerCreater is the callback function
}
function MarkerCreaterPlusLocation(input,callback){
location="l";
geocoder.geocode({'latLng': input}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
location=results[1].formatted_address;
callback(location,input);//I call the callback function upon the success of the result or otherwise
} else {
location="l";
callback(location,input);
}
} else {
location="l";
callback(location,input);
}
});
}
function MarkerCreater(l,x){
var marker = new google.maps.Marker({
position: x,
title: '#' + path.getLength()+l,
icon: 'images/beachflag.png',
map: map
});
///Some more javascript code
}
I guess I am making mistake here as this does not seem to work . Rather it gives a 404 error which makes it still more difficult for me to understand it . Please help
location="l"in MarkerCreaterPlusLocation()