Using a StreetMap dataset for geocoding with ArcGIS for Windows Mobile

The StreetMap dataset contains street networks that can be used for geocoding on a mobile device. The locators exposed by the StreetMap data can be used to return a number of results, which are refined through a series of filters to narrow the result set.

// Get the StreetName locator by City and State 
Locator streetLocator = _streetMapLayer.StreetMapDataset.Locators[0];
streetLocator.Reset();
// Get the first filter 
LocatorFilter _stateFilter = streetLocator.GetNextFilter();
_stateFilter.AppendToFilter(txtState.Text.Trim());
// Gets the city filter
LocatorFilter _cityFilter = streetLocator.GetNextFilter();
_cityFilter.AppendToFilter(txtCity.Text.Trim()); 
// Gets the street filter 
LocatorFilter _streetFilter = streetLocator.GetNextFilter();
_streetFilter.AppendToFilter(txtStreet.Text.Trim());
 // Gets the housenumber filter 
LocatorFilter _houseNumberFilter = streetLocator.GetNextFilter();
_houseNumberFilter.RemoveAllCharacters();
_houseNumberFilter.AppendToFilter(txtStreetNum.Text.Trim());
 // get the result 
AnalyzeGeoCodingResults(_houseNumberFilter);

Once the filters have been created and assigned to the locator, the next step is to get the results. As multiple results may be returned from the locator, normally all the results are provided to the user so they can choose the desired one. The locator may return no results, so it's important to check for this condition.

if(filter.GetResults().Count() <= 0)
{
  MessageBox.Show("Cannot find this address !"); 
  return;
}
// only get the first one 
LocatorResult result = filter.GetResults().First(); 
//foreach (LocatorResult result in filter.GetResults()) 
  {
  Location candidate = result.GetLocationCandidates().First(); 
  //foreach (LocatorCandidate candidate in result.GetCandidates())
  { 
  // if the map control has a mobile service, need to do the conversion.
  // coordinate = mobileService1.SpatialReference.FromWgs84(lon, lat);
  ptLocated = new ESRI.ArcGIS.Mobile.Geometries.Point(candidate.Coordinate); } }
}

Where to get the sample

The sample is available for download from ArcGIS Online.

1/7/2015