0

In the below code when I stop the code in FireBug, the "results" object is a nice array filled with good geocoded values.

However, the locations[] array I put it into is full of all "undefined" values.

Shouldn't that be impossible because I can see the results[0] each time working nicely?

 var locations = [];

    function makeCallback(addressIndex) {
        var geocodeCallBack = function (results, status) {
            if (status == "success") {
                locations[addressIndex] = results[0];
            }
        };
        return geocodeCallBack;
    }

    $(function() {
        for (var x = 0; x < addresses.length; x++) {
            $.getJSON('http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=' + addresses[x], null, makeCallback(x));
        }
    });

1 Answer 1

1

After line:

var geocodeCallBack = function (results, status) {

results is object with properties results, success, for example Object {results: Array[1], status: "OK"} so the line:

locations[addressIndex] = results[0];

has to be changed to

locations[addressIndex] = results.results[0];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.