I have a function to return which of two points is closer to a third point:

```
//returns true if address1 is closer to address0 than address2
function closer(address0,address1,address2) {
    console.log(getDistance(address0,address2) + "fun from closer")
    var d1 = getDistance(address0,address2)
    console.log(address0+" "+address2+" "+d1)
    var d2 = getDistance(address0,address1)
    console.log(address0+" "+address1+" "+d1)
    return (d1 > d2);
}

```

which uses another function which uses google maps api to calculate distance between two points:

```
function getDistance(address1, address2) {
    var directionsService = new google.maps.DirectionsService;
    var request = getRequest(address1,address2);
    directionsService.route(request, function (response, status) {
        if (status == google.maps.DirectionsStatus.OK) {
            console.log(response.routes[0].legs[0].distance.value+ " the value");
            return (response.routes[0].legs[0].distance.value);
        }
        else {
            window.alert('Directions request failed due to ' + status);
            return 0;
        }
  });

```

And this is the log from the browser:

```
undefinedfun from closer
11 Franklin Ave, Franklin Square, NY 11010, USA 11 Franklin Ave, Franklin Square, NY 11010, USA undefined
11 Franklin Ave, Franklin Square, NY 11010, USA grand canyon    undefined
0 the value
3906002 the value

```

Which indicates that while the value is present in the getDistance function for some reason it doens't make it to the closer function. Any ideas?

I did notice that the log is sort of "out of order", since the console logs in getDistance should really be before the console logs in closer, but I don't know if that means anything, all the more so what to do about it.