예제 #1
0
        public Location GetLocation(string relativeUrl)
        {
            var addressLine = GetSearchPath(relativeUrl);

            var location = _locationRepo.GetLocationBySearchedAddress(addressLine);

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

            if (_unknownAddresses.Keys.Contains(addressLine))
            {
                _unknownAddresses[addressLine] += 1;
                return(null);
            }

            if (Connected)
            {
                var response = _googleClient.GetGeocoding(addressLine);

                if (response.IsOk)
                {
                    location = CreateLocation(addressLine, null, response);
                    return(location);
                }
            }

            Debug.WriteLine($"Could not find location by name for {addressLine} ");
            _unknownAddresses[addressLine] = 1;

            return(null);
        }
예제 #2
0
        public Location GetLocation(string relativeUrl)
        {
            List <string> names   = relativeUrl.Split(new char[] { '\\' }).ToList();
            string        address = string.Join("+", names);

            address = Regex.Replace(address, @"[\d-]", string.Empty);
            address = address.Replace(" ", "+").Replace("-", "+");
            address = address.Replace("++", "+").Replace("++", "+");

            var location = _locationRepo.GetLocationBySearchedAddress(address);

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

            var response = _googleClient.GetGeocoding(address);

            if (response.IsOk)
            {
                location = new Location();  // _goo

                location.Id = _locationRepo.GetNewId();

                location.SearchedAddress = address;

                location.Country = response.GetCountry();
                location.City    = response.GetCity();

                location.DisplayName = BuildDisplayName(response.BestResult.GetCity(),
                                                        response.BestResult.GetState(),
                                                        response.BestResult.GetCountry());

                _newLocations.Add(location);
                location.ProviderContent = JsonConvert.SerializeObject(response);

                return(location);
            }
            return(null);
        }