I run the function calatuteRoute within which there is a call to the distanceBetweenToPointByDrive function But for some reason it did not enter the call of the distanceBetweenToPointByDrive function But straight skips to do the rest of the operations in the function calatuteRoute Anyone know what could be the problem? I would appreciate solutions.
Attached is the code:
app.component.ts
- calatuteRoute() {
- setTimeout(() => {
- this.distanceBetweenToPointByDrive(Destination.geometry.location.lat(),
- Destination.geometry.location.lng(), this.arr[0].Lat_Destination, this.arr[0].Lng_Destination)
- },3000)
-
- }
- distanceBetweenToPointByDrive(latExported: any, lngExported: any, LatDestination: any,
- LngDestination: any): calculationResult {
- const resulte: calculationResult = {
- distance: "",
- time: ""
- }
- debugger
- let pointX = new google.maps.LatLng(latExported, lngExported)
- let pointY = new google.maps.LatLng(LatDestination, LngDestination)
- const service = new google.maps.DistanceMatrixService();
-
- service.getDistanceMatrix(
- {
- origins: [pointX],
- destinations: [pointY],
- travelMode: google.maps.TravelMode.DRIVING,
- unitSystem: google.maps.UnitSystem.METRIC,
- avoidHighways: false,
- avoidTolls: false,
- },
- (response, status) => {
-
- if (status !== "OK") {
- alert("Error was: " + status);
- return
- } else {
- const originList = response.originAddresses;
- const destinationList = response.destinationAddresses;
- for (let i = 0; i < originList.length; i++) {
- const results = response.rows[i].elements;
- for (let j = 0; j < results.length; j++) {
- resulte.distance = results[j].distance.text;
- resulte.time = results[j].duration.text;
- }
- }
- }
- return resulte;
- }
- );
- return resulte;
- }