Search code examples
c#mapsbing

Cannot get RouteLegs from returned object in Bing maps .NET REST toolkit


I am using the Microsoft Bing Maps .NET REST Toolkit.

I try a route request like this:

    private async Task<Resource[]> CallTruckAPI(string apiKey, int minutes, bool currentTraffic, List<SimpleWaypoint> waypoints)
    {
        string key = apiKey;

        var routeRequest = new RouteRequest()
        {
            Waypoints = waypoints,
            WaypointOptimization = TspOptimizationType.TravelTime,
            RouteOptions = new RouteOptions()
            {
                TravelMode = TravelModeType.Driving
            },
            BingMapsKey = key
        };

        var response = await routeRequest.Execute();

        return response.ResourceSets[0].Resources;
    }

It returns resource sets and resources which I can access OK.

But when I try to get the RouteLegs out of the Resources I cannot get anything in C#.

Bing Maps data returned

I can peek them in Visual Studio, as you can see above, but cannot access them. Any ideas?


Solution

  • I figured this out. For each Bing Resource returned I needed to cast it as a Bing Route. Then I can get at the contents including the RouteLegs.

    I hope this helps someone!