I'm trying to build an array of latitudes and longitudes for start/end points for routing.
function parkRoute(){
var start = $('#start').val();
var end = $('#end').val();
var points = [];
function printPoints(points){
console.log(points)
}
function getXY(add){
geocoder.geocode( {'address': add + ", glendale, ca"}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0].geometry.location) {
var lon = results[0].geometry.location.kb;
var lat = results[0].geometry.location.jb;
points.push(lat,lon);
console.log(points)
}
}
})
}
getXY(start);
getXY(end);
printPoints(points);
}
It prints out an empty array first even though I'm calling another function to print them after the function to create the array.
[] parks1.js:192
[34.1480811, -118.24759369999998] parks1.js:201
[34.1480811, -118.24759369999998, 34.1851925, -118.27651679999997] parks1.js:201
What am I doing wrong?