The getJSON()
call is asynchronous, meaning map.geocodeAndAddLocations()
is being run while the network request is still out, and addresses
is empty.
Move your call to map.geocodeAndAddLocations()
into the callback in getJSON()
after assembling the addresses
array. (Also, why are you assembling an array of JSON strings?)