none
Calculate TollRoad distance RRS feed

  • Question

  • Hi, 

    Is possible to calculate the distance traveled on highways (tollroad) using the web service?

    I have this piece of code, but the results are not correct!!!

    public override double CalculateDistanceTollRoad(object route)
    {
    	RouteResponse routeResponse = route as RouteResponse;
    	double kmTollRoad = 0;
    
    	for (int k = 0; k < routeResponse.Result.Legs.Length; k++)
    	{               
    		for (int i = 0; i < routeResponse.Result.Legs[k].Itinerary.Length; i++)
    		{                   
    			if (TollRoadPresent(routeResponse.Result.Legs[k].Itinerary[i].Warnings))
    			{
    				kmTollRoad += routeResponse.Result.Legs[k].Itinerary[i].Summary.Distance;
    			}
    		}
    	}
    
    	return kmTollRoad;
    }
    private bool TollRoadPresent(ItineraryItemWarning[] itineraryItemWarning)
    {
    	foreach (ItineraryItemWarning item in itineraryItemWarning)
    	{
    		if (item.WarningType == ItineraryWarningType.TollRoad || item.WarningType == ItineraryWarningType.Tollbooth)
    		{
    			return true;
    		}
    	}
    
    	return false;
    }

    Thks,

    NS

    Friday, March 23, 2012 7:10 PM

Answers

  • This is not something that is meant to be extracted from the routing service. You will not get an accurate distance of a tool road by parsing the route intinerary.


    http://rbrundritt.wordpress.com

    Friday, April 13, 2012 11:22 AM

All replies

  • This is not something that is meant to be extracted from the routing service. You will not get an accurate distance of a tool road by parsing the route intinerary.


    http://rbrundritt.wordpress.com

    Friday, April 13, 2012 11:22 AM
  • According to the folks at Microsoft, it is not possible with Bing Service.

    Thank you... 

    NS

    Monday, April 16, 2012 10:34 AM
  • I think that's what Ricky said in his previous reply! (After all, Ricky is one of the folk from Microsoft :)

    twitter: @alastaira blog: http://alastaira.wordpress.com/

    Monday, April 16, 2012 11:15 AM
    Moderator
  • Exact "tanoshimi"... :), Richard confirms what had been told by microsoft (via email)

    NS

    Monday, April 16, 2012 7:04 PM
  • Another question: in Mappoint service was possible to obtain this information (distance traveled on highways)?
    Back then i had this code and the values were not many different from the real values (by knowledge or ViaMichelin)...

    public override double CalculateDistanceTollRoad(object route)
            {
                Route oRoute = (Route)route;
                double KmTollRoads = 0;
                //Iterate through each segment of the route
                foreach (Segment routeSegment in oRoute.Itinerary.Segments)
                {
                    //Output each direction of the segment
                    for (int i = 0; i < routeSegment.Directions.Length; i++)
                    {
                        string strItemText = "";
                        if (routeSegment.Directions[i] != null)
                        {
                            strItemText = routeSegment.Directions[i].Instruction.ToString() + " ";
                            if (strItemText.ToLower().IndexOf("*toll road*") >= 0)
                                KmTollRoads = KmTollRoads + routeSegment.Directions[i].Distance;
                        }
                    }
                }
    
                return KmTollRoads;
            }

    Wednesday, April 18, 2012 9:21 AM