One question that comes up quite often is. “What settings should I use for the geocoder to find a match?”
This answer will vary depending upon your application requirements and how important the accuracy of a match is to your application. To help answer this question for all audiences I have provided a code snippet below that shows how most programmers would use the settings to find various geocode match levels and accuracy.
In the function below we start with an ExactMatch search which is the most accurate and most desirable in almost all cases. Then we start to loosen the match criteria by removing Street Types & Street Directional’s. Next we check for a close street number in case the street number was miss keyed. After that we check for a street name misspelling and try to match to a street with a similar sound or spelling. After that we check nearby zip codes for the address and see if we can find a match, and finally if we can't find anything we can return the center point of the Zip code (Assuming it's a valid zip code).
private GeoCodeResult multiGeocode(string address, string city, string state, string zip,ref string matchLevel)
{
if (geoEngine == null)
{
try
{
geoEngine =
new GeoCodeEngine(this.txtDataDirectory.Text, false);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
return null;
}
}
GeoCodeUSASettings gcSettings = new GeoCodeUSASettings();
GeoCodeResult gcResult;
//Exact Match
gcSettings.ExactMatch =
true;
gcResult = geoEngine.AdvancedGeoCode(address, city, state, zip,
ref gcSettings);
if (gcResult.FailureCode == FailureCode.None)
{
matchLevel =
"Exact Match";
return gcResult;
}
//Ignore Street Directionals
gcSettings.ExactMatch =
false;
gcSettings.IgnoreDirectionals =
true;
gcResult = geoEngine.AdvancedGeoCode(address, city, state, zip,
ref gcSettings);
if (gcResult.FailureCode == FailureCode.None)
{
matchLevel =
"Ignore Street Directionals";
return gcResult;
}
//Ignore Street Type & Directionals
gcSettings.ExactMatch =
false;
gcSettings.IgnoreDirectionals =
true;
gcSettings.IgnoreStreetType =
true;
gcResult = geoEngine.AdvancedGeoCode(address, city, state, zip,
ref gcSettings);
if (gcResult.FailureCode == FailureCode.None)
{
matchLevel =
"Ignore Street Type & Directionals";
return gcResult;
}
//Found Closes Street Number
gcSettings.ExactMatch =
false;
gcSettings.IgnoreDirectionals =
true;
gcSettings.IgnoreStreetType =
true;
gcSettings.ClosestStreetNumber =
true;
gcSettings.FuzzyStreetName =
false;
gcResult = geoEngine.AdvancedGeoCode(address, city, state, zip,
ref gcSettings);
if (gcResult.FailureCode == FailureCode.None)
{
matchLevel =
"Found Closes Street Number";
return gcResult;
}
//Found Street with Similar Spelling (Possible Misspelled Street Name)
gcSettings.ExactMatch =
false;
gcSettings.IgnoreDirectionals =
true;
gcSettings.IgnoreStreetType =
true;
gcSettings.ClosestStreetNumber =
true;
gcSettings.FuzzyStreetName =
true;
gcResult = geoEngine.AdvancedGeoCode(address, city, state, zip,
ref gcSettings);
if (gcResult.FailureCode == FailureCode.None)
{
matchLevel =
"Fuzzy Street Name (Misspelled)";
return gcResult;
}
//Check Nearby Zip Codes
gcSettings.ExactMatch =
false;
gcSettings.IgnoreDirectionals =
true;
gcSettings.IgnoreStreetType =
true;
gcSettings.FuzzyStreetName =
true;
gcSettings.ClosestStreetNumber =
true;
gcSettings.NearbyZip =
true;
gcResult = geoEngine.AdvancedGeoCode(address, city, state, zip,
ref gcSettings);
if (gcResult.FailureCode == FailureCode.None)
{
matchLevel =
"Found a possible match in a near by zipcode.";
return gcResult;
}
//Return Zip Centroid
gcSettings.ExactMatch =
false;
gcSettings.IgnoreDirectionals =
true;
gcSettings.IgnoreStreetType =
true;
gcSettings.FuzzyStreetName =
true;
gcSettings.ClosestStreetNumber =
true;
gcSettings.NearbyZip =
true;
gcSettings.ZipCentroid =
true;
gcResult = geoEngine.AdvancedGeoCode(address, city, state, zip,
ref gcSettings);
//We should always find a Zip Centroid if the Zip code is valid
matchLevel =
"Zip Centroid";
return gcResult;
}