Cann't find the route.!!!

5/26/2013 4:13:33 AM
Total Posts 23

Cann't find the route.!!!

The sample code is here....


AspMap.Point start, end;
string roadNetworkFolder = MapPath("MAPS/ROUTING/");

// find coordinates of start and end locations
start = GetLocationCoordinate(startLocation.SelectedValue);
if (start == null) return;
end = GetLocationCoordinate(endLocation.SelectedValue);
if (end == null) return;

if (start.Equals(end))
errorMessage.Text = "Locations are equal.";

// load the road network
AspMap.Network roadNetwork;

if (Application["RoadNetwork"] == null)
roadNetwork = new AspMap.Network();

if (!roadNetwork.Open(roadNetworkFolder + "roads.shp", roadNetworkFolder + "roads.rtn"))
throw new Exception("Cannot load road network: " + MapPath("MAPS/ROUTING/roads.rtn"));

Application["RoadNetwork"] = roadNetwork;
roadNetwork = Application["RoadNetwork"] as AspMap.Network;

// create a Route object
AspMap.Route route = roadNetwork.CreateRoute();

// set the properties of the Route object
if (unitsList.SelectedItem.Value == "Miles")
route.DistanceUnit = MeasureUnit.Mile;
route.DistanceUnit = MeasureUnit.Kilometer;

if (routeTypeList.SelectedItem.Value == "Quickest")
route.RouteType = RouteType.Quickest;
route.RouteType = RouteType.Shortest;

route.MaxDistance = 0.5;

// find a route between two points
if (route.FindRoute(start.X, start.Y, end.X, end.Y))
// remove previous route layer

// merge the Segment objects of the Route to Street objects,
// the Street objects will be used to generate driving directions

// save the Route object to a session variable
Session["RouteObj"] = route;

// set the map extent to the route extent
map.Extent = route.Extent;
errorMessage.Text = "Route not found.";

5/26/2013 5:07:07 AM
Total Posts 329

Re: Cann't find the route.!!!

If you are using the full sample from the trial version and it is expired (after a 60-day trial period), the Route class will not work. This is a limitation of the expired trial version.