예제 #1
0
        public List <decimal?> GetProximity(string originAddress, List <string> destinationAddresses)
        {
            var originCoords = _addressGeocodingService.GetGeoCoordinates(originAddress);

            var numRequests = Math.Ceiling(destinationAddresses.Count / (decimal)MaxDestinationsPerRequest);

            var results = new List <decimal?>(destinationAddresses.Count);

            for (var i = 0; i < numRequests; i++)
            {
                var next = GetDistanceMatrix(originCoords, destinationAddresses.Skip(i * MaxDestinationsPerRequest).Take(MaxDestinationsPerRequest));
                results.AddRange(next.Rows[0].Elements.Select(e => e == null || e.NoResultsFound || e.Distance == null ? (decimal?)null : (decimal)Math.Round(e.Distance.Value / MetersPerMile * 10) / 10).ToList());
            }

            return(results);
        }
예제 #2
0
 private void SetGeoCoordinates(AddressDTO address)
 {
     try
     {
         var coords = _addressGeocodingService.GetGeoCoordinates(address);
         address.Longitude = coords.Longitude;
         address.Latitude  = coords.Latitude;
     }
     catch (InvalidAddressException e)
     {
         _logger.Info($"Can't get GeoCoordinates for address '{address}', address is invalid", e);
     }
     catch (Exception e)
     {
         _logger.Error($"Error getting GeoCoordinates for address '{address}'", e);
     }
 }
예제 #3
0
        public GeoCoordinate GetGeoLocationCascading(AddressDTO addressReal)
        {
            var address   = new AddressDTO(addressReal);
            var stateTemp = address.State;

            var coords = new GeoCoordinate();

            //get by the full address. If that fails get by city state. If that fails get by state only
            try
            {
                coords = _addressGeocodingService.GetGeoCoordinates(address);
            }
            catch (InvalidAddressException)
            {
                address.AddressLine1 = "";
                address.AddressLine2 = "";
                try
                {
                    coords = _addressGeocodingService.GetGeoCoordinates(address);
                }
                catch (InvalidAddressException)
                {
                    try
                    {
                        // only zip
                        address.City  = "";
                        address.State = "";
                        coords        = _addressGeocodingService.GetGeoCoordinates(address);
                    }
                    catch (InvalidAddressException)
                    {
                        try
                        {
                            // only state
                            address.State      = stateTemp;
                            address.PostalCode = "";
                            coords             = _addressGeocodingService.GetGeoCoordinates(address);

                            _logger.Debug("Address geocoded on state level.");
                        }
                        catch (InvalidAddressException)
                        {
                            _logger.Debug("Unable to geocode address.");
                        }
                    }
                }
            }
            return(coords);
        }
예제 #4
0
        public List <decimal?> GetProximity(string originAddress, List <AddressDTO> destinationAddresses)
        {
            var originCoords = _addressGeocodingService.GetGeoCoordinates(originAddress);

            return(destinationAddresses.Select(a => CalculateProximity(originCoords, a)).ToList());
        }