Currently, I am utilizing the Google Maps directions service to determine the estimated travel time.
this.mapsAPILoader.load().then(() => {
const p1 = new google.maps.LatLng(50.926217, 5.342043);
const p2 = new google.maps.LatLng(50.940525, 5.353626);
const directionsService = new google.maps.DirectionsService();
const request = {
origin: p1,
destination: p2,
travelMode: google.maps.TravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.METRIC,
};
directionsService.route(request, (response, status) => {
if (status === google.maps.DirectionsStatus.OK) {
const point = response.routes[0].legs[0];
// console.log(point.duration.text);
this.travelTimeDriving = point.duration.text;
}
});
});
While the console is displaying the accurate driving time duration, my variable `this.travelTimeDriving` remains empty.
I suspect that this issue is related to the callback function and scope, but unfortunately, I am unable to resolve it.
Moreover, since the route function does not return a promise, I am unable to utilize `.then()` for handling.