anna levin

anna levin

  • 2k
  • 19
  • 426

Calling a function within a function in Angular not work

Apr 20 2021 6:58 AM
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
  1. calatuteRoute() {    
  2.      setTimeout(() => {     
  3.      this.distanceBetweenToPointByDrive(Destination.geometry.location.lat(),     
  4.      Destination.geometry.location.lng(), this.arr[0].Lat_Destination, this.arr[0].Lng_Destination)           
  5.      },3000)    
  6.      //do more somthing..    
  7.      }
  8. distanceBetweenToPointByDrive(latExported: any, lngExported: any, LatDestination: any,     
  9.                    LngDestination: any): calculationResult {    
  10.     const resulte: calculationResult = {    
  11.     distance: "",    
  12.     time: ""    
  13.      }    
  14.   debugger    
  15.     let pointX = new google.maps.LatLng(latExported, lngExported)    
  16.     let pointY = new google.maps.LatLng(LatDestination, LngDestination)    
  17.     const service = new google.maps.DistanceMatrixService();    
  18.     
  19.     service.getDistanceMatrix(    
  20.     {    
  21.     origins: [pointX],    
  22.     destinations: [pointY],    
  23.     travelMode: google.maps.TravelMode.DRIVING,    
  24.     unitSystem: google.maps.UnitSystem.METRIC,    
  25.     avoidHighways: false,    
  26.     avoidTolls: false,    
  27.   },    
  28.   (response, status) => {    
  29.     
  30.     if (status !== "OK") {    
  31.       alert("Error was: " + status);    
  32.       return    
  33.     } else {    
  34.       const originList = response.originAddresses;    
  35.       const destinationList = response.destinationAddresses;    
  36.       for (let i = 0; i < originList.length; i++) {    
  37.         const results = response.rows[i].elements;    
  38.         for (let j = 0; j < results.length; j++) {    
  39.            resulte.distance = results[j].distance.text;    
  40.           resulte.time = results[j].duration.text;    
  41.         }    
  42.       }    
  43.     }    
  44.     return resulte;    
  45.    }    
  46.  );    
  47.    return resulte;    
  48. } 

Answers (1)