I am trying to write a method which will take in some data and try to find the coordinates using the .geocode method from the google maps API. Due to the data not being completely correct some of the data will not be found and therefore will not have a coord assigned to it. So i need a function to either store the coordinates for correct data or store "fail" for erroneous data. This is what i have:
function codeAdd(callback) {
geocoder.geocode( { 'address': geoName}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var arr = [results[0].geometry.location.lat(),results[0].geometry.location.lng()];
callback('ok',arr);
} else {
callback('fail',null);
}
});
}
function codeAddCall(){;
codeAdd(function(status,callback) {
if(status == 'ok'){
latArray.push(callback[0]);
lngArray.push(callback[1]);
console.log("add success");
}
if(status == 'fail'){
latArray.push("fail");
lngArray.push("fail");
}
if((latArray.length==lngArray.length)&&(latArray.length==infArray.length)){
convertToAssoc(infArray,latArray,lngArray);
}
});
}
However with the "status" condition it completes the data set correctly, i.e putting the results in the right places and any erroneous data is stored with "fail" in the lat and lng array. However it causes browsers to crash(latest versions of chrome and firefox). I really dont undertstand why this is breaking ? Still can't get anything working can anyone help ?