0

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 ?

  • i actually have the same issue. but the thing is when i run it while logged in, it works fine. but when i run it while i'm logged off (using scheduled task), the page crashes half way and doesn't query the google maps service. did you find any solution to this? – h-rai Feb 04 '16 at 05:14

1 Answers1

0

You made a typo:

function codeAddCall(){);
                       ^

Maybe this is why your code fails.

Star Brilliant
  • 2,916
  • 24
  • 32