Get driving directions sample customization

Discussion created by tereshenkov on May 17, 2011
Latest reply on Sep 10, 2013 by adandrea808
Hi all,

My aim is to create a web application where a user could click on the map or type in the address end and start points for the routing; the route will be calculated and shown on the map; the directions text will be shown on the html page to the user. This application I need exclusively for testing of the routing capabilities available via the ArcGIS Web API.

It seemed that the easiest way would be to customize the sample Get driving directions (http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jssamples_start.htm#jssamples/routetask_directions.html) to use European geocoding and routing services.

I have exchanged the locator and the routing services strings with the European services:

locator = new esri.tasks.Locator("http://tasks.arcgisonline.com/ArcGIS/rest/services/Locators/TA_Address_EU/GeocodeServer");


routeTask = new esri.tasks.RouteTask("http://tasks.arcgisonline.com/ArcGIS/rest/services/NetworkAnalysis/ESRI_Route_EU/NAServer/Route");

However, when trying to get the directions, I get the error message from the browser:

An error occured
Unable to complete  operation.
Required field '<i>Country</i>' must be specified

I understand that probably this coming from the code where the parsing of the input geocoding strings happen. I.e.

//Parse and geocode "from" address
        var fromArr = dojo.byId("fromTxf").value.split(","),
            fromAddress = { Address:fromArr[0], City:fromArr[1], State:fromArr[2], Zip:fromArr[3] };
        locator.addressToLocations(fromAddress, ["Loc_name"], function(addressCandidates) { configureRoute(addressCandidates, "from"); });

        //Parse and geocode "to" address
        var toArr = dojo.byId("toTxf").value.split(","),
            toAddress = { Address:toArr[0], City:toArr[1], State:toArr[2], Zip:toArr[3] };
        locator.addressToLocations(toAddress, ["Loc_name"], function(addressCandidates) { configureRoute(addressCandidates, "to"); });

However, I am not sure how one is supposed to edit this piece of code (or maybe others, too!) in order to reflect the European geocoding parameters (I've looked a bit at http://tasks.arcgisonline.com/ArcGIS/rest/services/Locators/TA_Address_EU/GeocodeServer).

I would appreciate if anyone could give me some tips what shall I look at. Maybe it is easier to customize the Find Route sample (http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jssamples_start.htm#jssamples/routetask_find_route.html) by implementing the routing directions there, but I am not that familiar with the JavaScript API.

Thank you.