Common Geocoding


Purpose
This sample illustrates how to use the Web Application Developer Framework (ADF) controls and Common Data Source application programming interface (API) (the Common API) to work with a geocode resource and geocode functionality regardless of data source type.
 
The GeocodeResourceManager control enables you to add a resource item associated with a service that has geocoding capabilities (for example, ArcGIS Server local and Internet or ArcIMS, ). To use geocode resources, the GeocodeResourceManager or the appropriate resource item (and resource) must be initialized at run time. If the geocode capabilities you need are available via the generic Common API IGeocodeFunctionality interface, you do not need to work with a specific data source implementation. In this case, you can call the Geocode method on IGeocodeFunctionality and work with Web ADF and Common API classes and properties.
 
This sample works with the following provided datasets:
  • RoadCenterline locator

How to use

Data has been provided for your use with this sample. It can be found at <Your ArcGIS Developer Kit Install directory>/Samples/data/BloomfieldTownship/RoadCenterline_Locator.
If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

At design time
  1. Verify that a map service and geocode service are available and that they share the same geographic area.
  2. Verify that the Web ADF for the .NET Framework is installed and functioning properly. For information on installing and configuring the Web ADF, consult the installation guide.
  3. In Windows Explorer, navigate to <ArcGIS install location>\DeveloperKit10.0\Samples\ServerNET. This folder contains the Common_Geocoding CSharp and VBNet folders.
  4. Open the folder of the language you're going to use—CSharp or VBNet—and copy the Common_Geocoding_<language> folder to c:\inetpub\wwwroot. The <language> variable can be either CSharp or VBNet.
  5. Open the IIS Manager from Control Panel > Administrative Tools > Internet Information Services (IIS) Manager or Internet Information Services.
  6. In the console tree view on the left, navigate to Local Computer > Web Sites > Default Web Site, expand Default Web Site, right-click the Common_Geocoding_<language> folder, and click Properties. The Properties dialog box opens.
  7. Click the Directory tab, click the Create button in the Application Settings section, then click OK to close the Properties dialog box.
  8. Start Microsoft Visual Studio and open the Common_Geocoding_<language><vs_version> solution (for example, Common_Geocoding_CSharp2008.sln) located in c:\inetpub\wwwroot\Common_Geocoding_<language>. The <vs_version> references the Visual Studio version of the solution, 2008 or 2010.
  9. In Solution Explorer, right-click Default.aspx and select Set As Start Page.
  10. Open the Default.aspx page in Design view, open the properties window for the MapResourceManager control, and click the ellipsis next to the ResourceItems property. The ResourceItem Collection Editor dialog box opens.
  11. Add or change the MapResourceItem associated with a map service (ArcGIS Server, ArcIMS, and so forth).
  12. Select the GeocodeResourceManager and click the ellipsis next to the ResourceItems property. The ResourceItem Collection Editor dialog box opens.
  13. Add or change the ResourceItem associated with a geocode service (ArcGIS Server, ArcIMS, and so forth).
  14. If necessary, set the run time identity of the Web application by following one of the next two steps. If not necessary, proceed to step 17.
  15. At design time, the identity of the user running Visual Studio is used to connect to an ArcGIS Server local data source. At run time, that identity is established by the Web application. Only one identity can be used to define access to the ArcGIS Server local data sources in a single Web application. This identity can be explicitly defined when building the Web ADF application in Visual Studio by right-clicking the Web project in Solution Explorer and selecting the Add ArcGIS Identity option. Enter the identity credentials that will be used to access ArcGIS Server local resources at run time. This information is added to the web.config file in a standard ASP.NET identity tag. If the Encrypt identity in web.config check box is checked, the identity tag will be encrypted; otherwise, the username and password are stored as clear text.
  16. Open the web.config file and add an <identity> element in <system.web>, set the impersonate attribute to true, and add a username and password attribute and set them to a valid user account. If you're working with ArcGIS Server local data sources, ensure the account has access to the geographic information system (GIS) server resources referenced in the Map control.
  17. Save the project.
  18. Click the Debug drop-down menu and click Start Debugging.

At run time
  1. Browse to the viewer uniform resource locator (URL) (for example, http://localhost/Common_Geocoding_CSharp).
  2. Type an address and ZIP Code, and click the Geocode button. Only one match (the one with the best score) is returned. Its coordinate location is displayed at the bottom of the page and a graphic point is rendered in a Web ADF graphics layer in the map.
  3. Click the Clear button. The coordinate text is removed from the page and the graphic element is removed from the map.
  4. Check the Get All Candidates check box.
  5. Type another address and click the Geocode button. The match candidates are displayed in a GridView at the bottom of the page. Each candidate is also displayed as a graphic point in the map.

Common_Geocoding_CSharp\Default.aspx User interface for the Web application.
Common_Geocoding_CSharp\Default.aspx.cs Code behind the user interface.
Download the C# files
Common_Geocoding_VBNet\Default.aspx User interface for the Web application.
Common_Geocoding_VBNet\Default.aspx.vb Code behind the user interface.
Download the VB.NET files

Download the files for all languages