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); }
private Location CreateLocation(string address, GeoPosition position, GeocodingRequestResult response) { Location location; location = new Location(); location.Id = _locationRepo.GetNewId(); location.SearchedAddress = address.RemoveDiacritics(); location.SearchedPosition = position; location.Position = new GeoPosition(response.results.First().Latitude, response.results.First().Longitude); location.Country = response.GetCountry(); location.City = response.GetCity(); location.State = response.GetState(); location.DisplayName = BuildDisplayName(location.City, location.State, location.Country); var exitingLocation = _locationRepo.GetLocation(location.DisplayName); if (exitingLocation != null) { return(exitingLocation); } location.Excluded = IsExcludedLocation(location) || IsInHomeArea(location); Debug.WriteLine($"New location for {address} {location.Id} {location.DisplayName} "); _newLocations.Add(location); _locationRepo.Add(location); SaveLocations(); return(location); }