Beispiel #1
0
        public static async Task <Direction> WalkDistance(GeoCoordinate source, GeoCoordinate target)
        {
            if (source == target)
            {
                return(new Direction());
            }

            var cachedValue = LookupCache(source, target);

            if (cachedValue != null)
            {
                return(cachedValue);
            }

            double straightLineDistance = source.GetDistanceTo(target);

            if (straightLineDistance < PlanMinimumInMeters)
            {
                return(defaultWalkDistance(straightLineDistance));
            }

            var res = await directionsService.WalkDistanceAsync(source.Latitude, source.Longitude, target.Latitude, target.Longitude);

            if (res == null)
            {
                res = defaultWalkDistance(straightLineDistance, true);
            }
            AddToCache(source, target, res);
            return(res);
        }