I am currently utilizing draggable markers along with 2 autocompletes to assist with obtaining directions. You can find more information about this setup here: https://developers.google.com/maps/documentation/javascript/examples/directions-draggable.
Within my code, I have a listener that captures events when the marker's position changes.
google.maps.event.addListener(directionsDisplay, 'directions_changed', function () {
var place1 = autocompleteFrom.getPlace();
var coord1 = [place1.geometry.location.lat(), place1.geometry.location.lng()];
var place2 = autocompleteTo.getPlace();
var coord2 = [place2.geometry.location.lat(), place1.geometry.location.lng()];
});
An issue arises when autocompleteFrom.getPlace() returns undefined if the user has not entered a location into the search box. This leads to difficulties in handling default locations for the autocompletes.
Is there a way to establish default locations for the autocompletes to mitigate this problem?