How to access turn by turn directions from RouteRequest Response in WPF? RRS feed

  • Question

  • I'm trying to adapt this TravellingSalesmenRouteSample project to display turn-by-turn directions but I can't seem to figure out how to actually extract the instructions from the response. 

    (unable to link the sample project directly but it's at github . com /microsoft/BingMapsRESTToolkit/tree/master/Samples/WPF/TravellingSalesmenRouteSample)

    What I've tried:

    var route = response.ResourceSets[0].Resources[0] as Route;
    var item = route.RouteLegs[0].ItineraryItems[0].Instruction.Text;

    But I'm not actually getting any data out of the RouteLegs or ItineraryItems arrays, instead getting an "object reference not set to an instance of an object" error. I'm sure there data is in there somewhere as the sample program is calculating and plotting accurate routes, I just need some help getting the text instructions. Thanks!

    Edit: ok it looks like the RouteLeg is populated with data, but ItineraryItems is null. Any idea why the ItineraryItems wouldn't populate as part of the RouteLeg?
    • Edited by Shawn Cheek Wednesday, August 28, 2019 4:31 PM
    Wednesday, August 28, 2019 2:58 PM

All replies

  • Hi Shawn,

    You could try something like this... https://brianlagunas.com/mapping-a-route-with-directions-using-the-bing-maps-wpf-control-beta/ but the post is pretty old.



    Wednesday, August 28, 2019 10:48 PM
  • Unfortunately that example relies on the retired SOAP services. I have a WinForms version of my application working well enough, but the problem is getting 2 billable transactions every time I run it (once for the static map imagery, once for the routing). I've been trying to get the WPF option to work so I could run these API calls off a session key instead of each run resulting in billable tx.

    With the WPF control the RouteLeg object should have an array ItineraryItems with Description.Text that would hold the plaintext turn-by-turns, I just can't figure out why the response from the MS sample project is null for those ItineraryItems.

    • Edited by Shawn Cheek Thursday, August 29, 2019 12:56 PM
    Thursday, August 29, 2019 12:55 PM
  • Hi Shawn, 

    I reached out to the engineering team to look at this post and they have the following guidance and recommendations for you:

    • They shouldn't use the WPF control for this. You can use the UWP control in a WPF app now if you want, but any new app should be UWP rather than WPF
    • The post mentions they want to take advantage of session keys which the UWP control will do. The map services automatically use a session key when a map control is instantiated.
    • I don’t think they actually want to do turn-by-turn in the sense that we mean that term. They’re just asking how to extract the individual instructions from a route result. These are available through the route result on UWP – see:https://docs.microsoft.com/en-us/uwp/api/windows.services.maps.maproutemaneuver



    Thursday, August 29, 2019 3:55 PM
  • Thanks for checking with them. Unfortunately I can't go the UWP route as our organization is still months away from getting 1903, so the WPF control is all I have. Is there truly no wait to populate the ItineraryItems property in the WPF controls's response?

    Thursday, August 29, 2019 5:39 PM
  • You should be able to use the UWP MapRoute API from within a WPF app from version 1809 forward. Since the map service API has no UI it may even work prior to that, I haven't tested it.
    Friday, August 30, 2019 5:01 PM