When i use DirectionService to place coordinates into a polyline... i realize, that variable polyline outside the callback function wasn't changed at all.. and i also tried it for variable x.. and it was the same.. i just want this code to works.. is there anyway to make variable outside callback changed when it changed on callback scope ?
var polyline = new google.maps.Polyline({
    path: [],
    strokeColor: '#FF0000',
    strokeWeight: 3});
    var x = 0;
    DirectionService.route(request, function(result, status) {
        x = 1;
        if (status == google.maps.DirectionsStatus.OK)
        {
            var legs = result.routes[0].legs;       
            for ( i = 0; i < legs.length; i++) {
                var steps = legs[i].steps;
                for ( j = 0; j < steps.length; j++) {
                    var nextSegment = steps[j].path;
                    for ( k = 0; k < nextSegment.length; k++) {
                        polyline.getPath().push(nextSegment[k]);]
                    }
                }
            }
        console.log(polyline.getPath().getArray().length); // not zero
        console.log(x) // x = 1;
    }
});
map = new google.maps.Map(document.getElementById("googleMap"),mapProp);
console.log(polyline.getPath().getArray().length); // the array length is 0
console.log(x) // x remains ZERO!!
 
    