public static void RefineAddressWithGeography(IAddressGeography addr) { UspsLookupResult usps = GeographyServices.LookupUspsAddress(addr); if (usps.Result == LookupResult.Success) { addr.Quality = (addr.Quality & 0xfff0) | 0x01; addr.CopyFrom(usps); Match suffixMatch = Regex.Match(addr.Street, "^(.+) (APT|BSMT|#|BLDG|DEPT|FL|FRNT|HNGR|KEY|LBBY|LOT|LOWR|OFC|PH|PIER|REAR|RM|SIDE|SLIP|SPC|STOP|STE|TRLR|UNIT|UPPR)(.*)$"); string suffix = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(suffixMatch.Groups[2].Value.ToLowerInvariant()) + suffixMatch.Groups[3].Value; MapsLookupResult maps = GeographyServices.GeocodeAddress(usps); if (maps.Result == LookupResult.Success) { addr.Quality = (addr.Quality & 0xff0f) | (maps.Quality << 4); string mapsStreet = maps.Street + (suffixMatch.Success ? (" " + suffix) : ""); if (addr.Street.Equals(mapsStreet, StringComparison.OrdinalIgnoreCase)) { addr.CopyFrom(maps); addr.Street = mapsStreet; } addr.Location = maps.Geography; } } }
public static void RefineAddressWithGeography(IAddressGeography addr) { MapsLookupResult maps = GeographyServices.GeocodeAddress(addr); if (maps.Result == LookupResult.Success) { addr.Quality = maps.Quality; addr.Location = maps.Geography; } }