<script language="C#" runat="server"> public class GeoLocation { public string label; public double x; public double y; public GeoLocation( Map map, string label, double lat, double lon) { Projection proj = map.getProjection(); GeoPoint pt = proj.project( lat, lon); this.label = label; this.x = pt.x; this.y = pt.y; } } public static GeoRectangle inflateRect(GeoRectangle r, double percVal) { double dx = ((r.right - r.left) * percVal) / 100.0; double dy = ((r.top - r.bottom) * percVal) / 100.0; r.left = r.left - dx; r.top = r.top + dy; r.right = r.right + dx; r.bottom = r.bottom - dy; return (r); } </script> <% Map map = OpenMap(); // get the RoutingProblem object RoutingProblem rProblem = map.getRouting().createRoutingProblem(); // set routing stops array GeoLocation[] stops = new GeoLocation[4]; stops[0] = new GeoLocation (map, "Redlands, CA", 34.0528, -117.1531); stops[1] = new GeoLocation (map, "Loma Linda, CA", 34.0484, -117.2629); stops[2] = new GeoLocation (map, "San Bernardino, CA", 34.1214, -117.3046); stops[3] = new GeoLocation (map, "Highland, CA", 34.1282, -117.2106); RoutingStop rStop; // add routing stops for(int i = 0; i < stops.Length; i++) { rStop = new RoutingStop(); rStop.setStop(new GeoPoint( stops[i].x, stops[i].y)); rStop.setLabel(stops[i].label); rProblem.addStop(rStop); } rProblem.setHighwayPreference( 50); rProblem.setWeight(RoutingProblem.rmShortest); // to find quickest use rmQuickest rProblem.setOptimize( false); // no optimization Routing routing = map.getRouting(); string RouteID = routing.findRoute(rProblem, true, -1); // show the route routing.setRoute( RouteID); GeoRectangle r = routing.getDrivingDirections( RouteID).getExtent(); map.setExtent( inflateRect(r, 10)); // increase borders // print driving directions DrivingDirections DDirs = routing.getDrivingDirections( RouteID); DirectionsSegment DSeg; Response.Write( "<p>"+DDirs.getStartText()+"<br>\n"); Response.Write( DDirs.getFinishText()+"<br>\n"); Response.Write( DDirs.getTotalText()+"<p>\n"); for( int i=0; i < DDirs.getSegmentCount(); i++) { DSeg = DDirs.getSegment( i); Response.Write( (i+1)+". " + DSeg.getText() + "<br>\n"); // if there is TimeLengthText if( DSeg.getSegmentType() != DirectionsSegmentType.rmArrive && DSeg.getSegmentType() != DirectionsSegmentType.rmDepart) Response.Write( DSeg.getTimeLengthText() + "<br>\n"); } %>![]()