Network Analyst routing


Purpose
This sample provides point-to-point driving directions. You enter two addresses, and the sample returns an interactive map showing the route and driving directions. Directions can be reversed, and a printable version of the page is available.

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/SanFranciscoNetwork.
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.

Publish a network analysis service
  1. Start ArcCatalog and browse to <ArcGIS install location>\DeveloperKit10.0\Samples\data\SanFrancisco.
  2. Right-click SanFrancisco.mxd and click Publish to ArcGIS Server.
  3. Type SanFrancisco as the service name and click Next.
  4. Confirm that Network Analysis is checked and click Next.
  5. Click Finish.

Publish a geocoding service
  1. Right-click SanFranciscoLocator and click Publish to ArcGIS Server.
  2. Type SanFranciscoLocator as the service name and click Next.
  3. Click Finish and exit ArcCatalog.

Install the routing sample code
  1. Verify that the Web Application Developer Framework (ADF) for the .NET Framework is installed and functioning properly. For information on installing and configuring the Web ADF, consult the installation guide.
  2. In Windows Explorer, navigate to <ArcGIS install location>\DeveloperKit10.0\Samples\ServerNET. This folder contains ArcGIS_Routing CSharp and VBNet folders.
  3. Open the folder of the language you're going to use—CSharp or VBNet—and copy the ArcGIS_Routing_<language> folder to c:\inetpub\wwwroot. The <language> variable can be either CSharp or VBNet.
  4. Open the IIS Manager from Control Panel > Administrative Tools > Internet Information Services (IIS) Manager or Internet Information Services.
  5. In the console tree view on the left, navigate to Local Computer > Web Sites > Default Web Site, expand Default Web Site, right-click the ArcGIS_Routing_<language> folder, and click Properties. The Properties dialog box opens.
  6. Click the Directory tab, click the Create button in the Application Settings section, then click OK to close the Properties dialog box.
  7. Start Microsoft Visual Studio. Open the solution for the version of Visual Studio you're using. The Visual Studio version is appended to the solution file name. For example, the Visual Studio 2008 solution file for the ArcGIS_Routing_CSharp sample is ArcGIS_Routing_CSharp2008.sln and is located in the c:\inetpub\wwwroot\ArcGIS_Routing_CSharp folder.
  8. In Solution Explorer, right-click Default.aspx and select Set As Start Page.
  9. Change the identity specified in web.config manually or by right-clicking the project and clicking Add ArcGIS Identity. The user account specified must have access to the geographic information system (GIS) server resources referenced in the Map control.
  10. Build the project.
  11. Save the project.

Execute the routing sample
  1. Run the Web application.
  2. On the default page, enter the starting and ending addresses to use for generating a route and driving directions.
  3. Click the Get Directions button.
  4. On the Directions page, use the ZoomIn, ZoomOut, Pan, and Show Entire Route tools to interact with the map. Clicking an individual link in the directions list zooms the map to that step of the route. Clicking the Reverse Directions link inverts the list of driving directions.
  5. Click the Printable Version link to open a window containing the current map display and a formatted list of the driving directions.

Additional information

Using the sample with your own data
  • This sample uses the SanFranciscoNetwork data that is installed with the software development kit (SDK). To use your own data with this sample, read the data requirements and refer to the documentation on designing and building a network dataset in the ArcGIS Desktop Help > Contents tab > Extensions > Network Analyst.
  • The network dataset must be built to include driving directions and a cost attribute, usually based on distance or time. Having a cost attribute based on time allows the sample to return driving directions with time information. If a time attribute is not included, the time values displayed in the sample will be blank.
  • The map document must contain the network dataset and a route analysis layer.
  • The geocoding locator must use data with the same coordinate system as the network dataset.


ArcGIS_Routing_CSharp\App_Code\AssemblyInfo.cs Describes the assembly and specific versioning information.
ArcGIS_Routing_CSharp\App_Code\CustomTools.cs Code to handle when the user clicks the toolbar buttons.
ArcGIS_Routing_CSharp\Default.aspx User interface for entering the addresses between which the route and driving directions are based.
ArcGIS_Routing_CSharp\Default.aspx.cs Code behind Default.aspx.
ArcGIS_Routing_CSharp\Directions.aspx User interface for interacting with a map of the route and the driving directions.
ArcGIS_Routing_CSharp\Directions.aspx.cs Code behind Directions.aspx.
ArcGIS_Routing_CSharp\ErrorPage.aspx User interface for presenting application errors.
ArcGIS_Routing_CSharp\ErrorPage.aspx.cs Code behind ErrorPage.aspx.
ArcGIS_Routing_CSharp\GenerateImage.aspx Displays the map image for PrintPage.
ArcGIS_Routing_CSharp\GenerateImage.aspx.cs Code behind GenerateImage.aspx.
ArcGIS_Routing_CSharp\Global.asax Code for responding to application-level events raised by ASP.NET or HttpModules.
ArcGIS_Routing_CSharp\App_Code\Global.asax.cs Code behind Global.asax.
ArcGIS_Routing_CSharp\App_Code\IBaseRouteFinderPage.cs Base interface for the Route Finder Web page.
ArcGIS_Routing_CSharp\App_Code\NetworkAnalystRouteResult.cs Result from a Network Analyst Solve operation on route layers.
ArcGIS_Routing_CSharp\App_Code\NetworkAnalystUtility.cs Utility class for working with Network Analyst.
ArcGIS_Routing_CSharp\App_Code\CustomMapHandler.cs A custom MapHandler, enabled via entries in web.config. Calls methods in ServerObjectStateModifier.cs where required.
ArcGIS_Routing_CSharp\App_Code\ServerObjectStateModifier.cs Manages stateful changes to a stateless server object. Called from Directions.aspx.cs and CustomMapHandler.cs.
ArcGIS_Routing_CSharp\PrintPage.aspx User interface that presents a map and formatted driving directions for printing.
ArcGIS_Routing_CSharp\PrintPage.aspx.cs Code behind PrintPage.aspx.
ArcGIS_Routing_CSharp\StyleSheet.css StyleSheet file.
ArcGIS_Routing_CSharp\Web.config Application configuration files containing settings specific to this sample.
Download the C# files
ArcGIS_Routing_VBNet\App_Code\AssemblyInfo.vb Describes the assembly and specific versioning information.
ArcGIS_Routing_VBNet\App_Code\CustomTools.vb Code to handle when the user clicks the toolbar buttons.
ArcGIS_Routing_VBNet\Default.aspx User interface for entering the addresses between which the route and driving directions are based.
ArcGIS_Routing_VBNet\Default.aspx.vb Code behind Default.aspx.
ArcGIS_Routing_VBNet\Directions.aspx User interface for interacting with a map of the route and the driving directions.
ArcGIS_Routing_VBNet\Directions.aspx.vb Code behind Directions.aspx.
ArcGIS_Routing_VBNet\ErrorPage.aspx User interface for presenting application errors.
ArcGIS_Routing_VBNet\ErrorPage.aspx.vb Code behind ErrorPage.aspx.
ArcGIS_Routing_VBNet\GenerateImage.aspx Displays the map image for PrintPage.
ArcGIS_Routing_VBNet\GenerateImage.aspx.vb Code behind GenerateImage.aspx.
ArcGIS_Routing_VBNet\Global.asax Code for responding to application-level events raised by ASP.NET or HttpModules.
ArcGIS_Routing_VBNet\App_Code\Global.asax.vb Code behind Global.asax.
ArcGIS_Routing_VBNet\App_Code\IBaseRouteFinderPage.vb Base interface for the Route Finder Web page.
ArcGIS_Routing_VBNet\App_Code\NetworkAnalystRouteResult.vb Result from a Network Analyst Solve operation on route layers.
ArcGIS_Routing_VBNet\App_Code\NetworkAnalystUtility.vb Utility class for working with Network Analyst.
ArcGIS_Routing_VBNet\App_Code\CustomMapHandler.vb A custom MapHandler, enabled via entries in web.config. Calls methods in ServerObjectStateModifier.vb where required.
ArcGIS_Routing_VBNet\App_Code\ServerObjectStateModifier.vb Manages stateful changes to a stateless server object. Called from Directions.aspx.vb and CustomMapHandler.vb.
ArcGIS_Routing_VBNet\PrintPage.aspx User interface that presents a map and formatted driving directions for printing.
ArcGIS_Routing_VBNet\PrintPage.aspx.vb Code behind PrintPage.aspx.
ArcGIS_Routing_VBNet\StyleSheet.css StyleSheet file.
ArcGIS_Routing_VBNet\Web.config Application configuration files containing settings specific to this sample.
Download the VB.NET files

Download the files for all languages