locked
Is it possible to calculate and draw a route (C# xaml) ? RRS feed

  • Question

  • Hello I wanted to know if I could, I really tried and I know this is possible in Ajax, but unfortunately, in XAML everything I've tried only works for the previous version (for example i can't insert a MapPolyline in the child of the maplayer). I am grateful and forgive my bad English
    Friday, April 27, 2012 10:40 AM

Answers

  • You can calculate the route using the bing maps REST service: http://msdn.microsoft.com/en-us/library/ff701717.aspx

    To put a MapPolyline on the Map there's a code example in the MapPolyline help: http://msdn.microsoft.com/en-us/library/hh846499.aspx

    Map shapes (MapPolygon and MapPolyline) need to be in the ShapeLayers collection, not Children.

            <bm:Map >
                <bm:Map.ShapeLayers>
                    <bm:MapShapeLayer>
                        <bm:MapShapeLayer.Shapes>
                            <bm:MapPolygon FillColor="#FFEA0000" Visible="True">
                                <bm:MapPolygon.Locations>
                                    <bm:Location Longitude="-10" Latitude="-10"/>
                                    <bm:Location Longitude="10" Latitude="-10"/>
                                    <bm:Location Longitude="10" Latitude="10"/>
                                    <bm:Location Longitude="-10" Latitude="10"/>
                                </bm:MapPolygon.Locations>
                            </bm:MapPolygon>
                            <bm:MapPolyline Color="Black" Visible="True" Width="1"/>
                        </bm:MapShapeLayer.Shapes>
                    </bm:MapShapeLayer>
                </bm:Map.ShapeLayers>
            </bm:Map>
    

    • Proposed as answer by Kristoffer Henriksson Friday, April 27, 2012 4:47 PM
    • Marked as answer by Seuly Friday, April 27, 2012 5:57 PM
    Friday, April 27, 2012 4:47 PM
  • You have to use the routing service to snap your MapPolyline to the road. Simply pass in your coordinates into the Bing Maps REST routing service and retrieve the coordinates along the road, then use these to create your MapPolyline. Here is a blog post on how to use the REST services in .NET: http://rbrundritt.wordpress.com/2012/01/06/bing-maps-rest-service-net-libraries/

    http://rbrundritt.wordpress.com

    Saturday, April 28, 2012 10:43 AM

All replies

  • You can calculate the route using the bing maps REST service: http://msdn.microsoft.com/en-us/library/ff701717.aspx

    To put a MapPolyline on the Map there's a code example in the MapPolyline help: http://msdn.microsoft.com/en-us/library/hh846499.aspx

    Map shapes (MapPolygon and MapPolyline) need to be in the ShapeLayers collection, not Children.

            <bm:Map >
                <bm:Map.ShapeLayers>
                    <bm:MapShapeLayer>
                        <bm:MapShapeLayer.Shapes>
                            <bm:MapPolygon FillColor="#FFEA0000" Visible="True">
                                <bm:MapPolygon.Locations>
                                    <bm:Location Longitude="-10" Latitude="-10"/>
                                    <bm:Location Longitude="10" Latitude="-10"/>
                                    <bm:Location Longitude="10" Latitude="10"/>
                                    <bm:Location Longitude="-10" Latitude="10"/>
                                </bm:MapPolygon.Locations>
                            </bm:MapPolygon>
                            <bm:MapPolyline Color="Black" Visible="True" Width="1"/>
                        </bm:MapShapeLayer.Shapes>
                    </bm:MapShapeLayer>
                </bm:Map.ShapeLayers>
            </bm:Map>
    

    • Proposed as answer by Kristoffer Henriksson Friday, April 27, 2012 4:47 PM
    • Marked as answer by Seuly Friday, April 27, 2012 5:57 PM
    Friday, April 27, 2012 4:47 PM
  • thank you, you have been very helpfull !
    Friday, April 27, 2012 5:57 PM
  • Hello, 

    Thank you for your answer!

    With Seuly, we are both working on the development of a Metro Style App, using c# & XAML.

    We would like to include into our application the creation of roads, as into an application that uses Maps AJAX Control 7.

    With a MapPolyline, we're able to put lines on the map, but these lines don't follow the roads drawn on the map, as the module "Create driving route" here : http://www.bingmapsportal.com/isdk/ajaxv7#DirectionsModule2.

    Is it possible to include such a module, using c# & XAML ?

    (Forgive me for the faults!)

    Thank You, 
    Corentin

    Saturday, April 28, 2012 9:36 AM
  • You have to use the routing service to snap your MapPolyline to the road. Simply pass in your coordinates into the Bing Maps REST routing service and retrieve the coordinates along the road, then use these to create your MapPolyline. Here is a blog post on how to use the REST services in .NET: http://rbrundritt.wordpress.com/2012/01/06/bing-maps-rest-service-net-libraries/

    http://rbrundritt.wordpress.com

    Saturday, April 28, 2012 10:43 AM