public GoogleSearchAddressResponse GetLocationFullString(int CountryId, string Country, string strAddress) { GoogleSearchAddressResponse location = new GoogleSearchAddressResponse(); List<Address> points = new List<Address>(); GeoResponse r = GetGoogleLocation(strAddress); if (r != null) { if ((r.Status == "OK")) { location.SearchResult = (int)LocationSearchResultEnum.Found; var v = r.Results.ToList(); foreach (var rr in v) { Address s_addr = new Address(); GeoResponse.CResult.CGeometry.CLocation loc = rr.Geometry.Location; s_addr.Latitude = loc.Lat; s_addr.Longitude = loc.Lng; s_addr.FullAddressString = rr.formatted_address; s_addr.LocationType = rr.Geometry.LocationType; string sNum = "", sStreet = "", sCity = "", sState = ""; GeoResponse.CResult.GeocodeAddressComponent[] addrc = rr.AddressComponents; List<GoogleAddressPartsToDB> addrDbProps = GetCountryGoogleProps(CountryId); if ((addrDbProps != null) && (addrDbProps.Count > 0)) { List<GeoResponse.CResult.GeocodeAddressComponent> responseComponents = addrc.ToList(); sState = GetAddressPartString(2, responseComponents, addrDbProps); sCity = GetAddressPartString(3, responseComponents, addrDbProps); sStreet = GetAddressPartString(4, responseComponents, addrDbProps); sNum = GetAddressPartString(5, responseComponents, addrDbProps); s_addr.Building = sNum; s_addr.Street = sStreet; s_addr.City = sCity; s_addr.State = sState; s_addr.Country = Country; } else { for (int i = 0; i < addrc.Length; i++) { string sprop = addrc[i].Type[0]; if (sprop == "street_number") sNum = addrc[i].ShortName; if (sprop == "route") sStreet = addrc[i].ShortName; if (sprop == "administrative_area_level_1") sState = addrc[i].ShortName; if (sprop == "locality") sCity = addrc[i].ShortName; } } s_addr.Building = sNum; s_addr.Street = sStreet; s_addr.City = sCity; s_addr.State = sState; s_addr.Country = Country; points.Add(s_addr); } } else if (r.Status == "ZERO_RESULTS") { location.SearchResult = (int)LocationSearchResultEnum.NotFound; } else if (r.Status == "REQUEST_DENIED") { location.SearchResult = (int)LocationSearchResultEnum.RequestDenied; } else if (r.Status == "OVER_QUERY_LIMIT") { location.SearchResult = (int)LocationSearchResultEnum.OverProcessCountLimit; } else location.SearchResult = (int)LocationSearchResultEnum.Error; } location.ServiceResponseAddresses = points; return location; }
public GoogleSearchAddressResponse GetLocation(Address address) { string strAddress = BuildAddressString(address); GoogleSearchAddressResponse location = new GoogleSearchAddressResponse(); List <Address> points = new List <Address>(); GeoResponse r = GetGoogleLocation(strAddress); if (r != null) { if ((r.Status == "OK")) { location.SearchResult = (int)LocationSearchResultEnum.Found; var v = r.Results.ToList(); foreach (var rr in v) { Address s_addr = new Address(); GeoResponse.CResult.CGeometry.CLocation loc = rr.Geometry.Location; s_addr.Latitude = loc.Lat; s_addr.Longitude = loc.Lng; s_addr.FullAddressString = rr.formatted_address; s_addr.LocationType = rr.Geometry.LocationType; string sNum = "", sStreet = "", sCity = "", sState = ""; GeoResponse.CResult.GeocodeAddressComponent[] addrc = rr.AddressComponents; List <GoogleAddressPartsToDB> addrDbProps = GetCountryGoogleProps(address.CountryId); if ((addrDbProps != null) && (addrDbProps.Count > 0)) { List <GeoResponse.CResult.GeocodeAddressComponent> responseComponents = addrc.ToList(); sState = GetAddressPartString(2, responseComponents, addrDbProps); sCity = GetAddressPartString(3, responseComponents, addrDbProps); sStreet = GetAddressPartString(4, responseComponents, addrDbProps); sNum = GetAddressPartString(5, responseComponents, addrDbProps); s_addr.Building = sNum; s_addr.Street = sStreet; s_addr.City = sCity; s_addr.State = sState; s_addr.Country = address.Country; } else { for (int i = 0; i < addrc.Length; i++) { string sprop = addrc[i].Type[0]; if (sprop == "street_number") { sNum = addrc[i].ShortName; } if (sprop == "route") { sStreet = addrc[i].ShortName; } if (sprop == "administrative_area_level_1") { sState = addrc[i].ShortName; } if (sprop == "locality") { sCity = addrc[i].ShortName; } } } s_addr.Building = sNum; s_addr.Street = sStreet; s_addr.City = sCity; s_addr.State = sState; s_addr.Country = address.Country; points.Add(s_addr); } } else if (r.Status == "ZERO_RESULTS") { location.SearchResult = (int)LocationSearchResultEnum.NotFound; } else if (r.Status == "REQUEST_DENIED") { location.SearchResult = (int)LocationSearchResultEnum.RequestDenied; } else if (r.Status == "OVER_QUERY_LIMIT") { location.SearchResult = (int)LocationSearchResultEnum.OverProcessCountLimit; } else { location.SearchResult = (int)LocationSearchResultEnum.Error; } } location.ServiceResponseAddresses = points; return(location); }