Here I am calculating the distance and time between two latitude and longitude points.Almost I am getting the answer but I am not able to return the value to the function.
Please help me. Thanks in advance
My codings are :
function initMap() {
         console.log(getDistanceandTime(srcRouteAddress.lat,srcRouteAddress.lng,destRouteAddress.lat,destRouteAddress.lng));
        function getDistanceandTime(lat1,lon1,lat2,lon2){
        var origin = {lat: parseFloat(lat1), lng: parseFloat(lon1)};
        var destination = {lat: parseFloat(lat2), lng: parseFloat(lon2)};
        var service = new google.maps.DistanceMatrixService;
        //var test = [];
        service.getDistanceMatrix({
            origins: [origin],
            destinations: [destination],
            travelMode: google.maps.TravelMode.DRIVING
        }, function (response, status) {
            if (status == google.maps.DistanceMatrixStatus.OK) {
                var test_values = [];
                var originList = response.originAddresses;
                for (var i = 0; i < originList.length; i++) {
                    var results = response.rows[i].elements;
                    for (var j = 0; j < results.length; j++) {
                        var test = results[j].distance.text + ' in ' + results[j].duration.text;
                        test_values.push(test);
                        console.log(test_values);
                    }
                }
                return test_values;
            }
            return test_values;
        });
    }
   }
 
     
     
     
    