Beispiel #1
0
        /// <summary>
        /// Calculates the distance between two addresses and returns the distance.
        /// </summary>
        /// <param name="first">The first address.</param>
        /// <param name="second">The second address.</param>
        /// <returns>The distance between the two addresses.</returns>
        private async Task <decimal> GetDistanceInKilometersAsync(Address first, Address second)
        {
            //Validate the addresses
            var firstAsString       = first.ToString();
            var secondAsString      = second.ToString();
            var validateOrigin      = _googleMapsApiService.ValidateAddressAsync(first);
            var validateDestination = _googleMapsApiService.ValidateAddressAsync(second);
            await Task.WhenAll(validateOrigin, validateDestination);

            //Validation ok (otherwise an exception would be thrown above)
            var distanceInKm = await _googleMapsApiService.GetDistanceInKmAsync(firstAsString, secondAsString);

            return(distanceInKm);
        }