While working on implementing an autocomplete with JavaScript and the Google Maps geocode method (using the keyup event on input), I have encountered a problem where I sometimes receive the results of the previous search instead of the current one.
I am looking for a way to cancel the previous call if it has not finished yet. Can anyone provide assistance?
getAddressLatLng : function(text,callback) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
address : text,
region : Utils.getRegion()
},
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
callback(results);
}
});
},