markers.length
will (most likely) always be 1 or more. Therefore you'll get the error on every first cycle, markers[0-1]
will always be undefined. Use
if (i > 0) {
place = markers[i].position;
console.log(place);
lastPlace = markers[i-1].position;
console.log(lastPlace);
calcRoute();
}
or
for (var i = markers.length; i>1; i--) {
place = markers[i].position;
console.log(place);
lastPlace = markers[i-1].position;
console.log(lastPlace);
calcRoute();
}
instead.