save the result of a function getDistanceMatrix in a variable : <p>I am trying to save the result of a function in a variable </p>

<pre><code>let myDistance = (()=&gt;{
   let service = new google.maps.DistanceMatrixService();

   service.getDistanceMatrix(
   {
       origins: [{lat: 55.93, lng: -3.118}],
       destinations: [{lat: 50.087, lng: 14.421}],
       travelMode: google.maps.TravelMode.DRIVING,
       avoidHighways: false,
       avoidTolls: false
   }, callback );

   function callback(response, status) {
         let distance = 0;
         if(status=="OK") {
             distance = response.rows[0].elements[0].distance.value;
         } else {
             alert("Error: " + status);
         }
         return distance;
   }
})();
console.log(myDistance)
</code></pre>

<p>But not working
I use Google Maps Api v3 - Distance Matrix section</p>

<pre><code>&lt;script async defer
   src="https://maps.googleapis.com/maps/api/jskey=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"&gt;
&lt;/script&gt;
</code></pre>
