locked
how to display custom flags for the waypoints in the route on the map using bing map AJAX API? RRS feed

  • Question

  • I want to display custom flags for the for the intermediate waypoints in the route on the map using Bing Map AJAX API.

    I know in callback function of map.GetDirection we can get get lat/long of the points present in  route legs we can make use of that. I can able to show custom flags for start address & destination by using following code:

        var startPoint = new VEShape(VEShapeType.Pushpin, route.RouteLegs[0].StartLocation);
            startPoint.SetCustomIcon("/Content/Images/flag_green_a_transparent.png");
            startPoint.SetZIndex(2001, 2000);
            slRoute.AddShape(startPoint);

     var finalImageName = "/Content/Images/flag_red_b_transparent.png";
            var endPoint = new VEShape(VEShapeType.Pushpin, route.RouteLegs[numLegs - 1].EndLocation);
            endPoint.SetCustomIcon(finalImageName);
            endPoint.SetZIndex(2002, 2000);
            slRoute.AddShape(endPoint);


    But how can I show custom flags for intermediate waypoints in the route? Because sometime lat/long of the added waypoints doesn't match with lat/long of points in the route legs.

    Is Bing doing some rounding of lat/long of points returned in the route legs?
    • Moved by Ricky_Brundritt Friday, March 9, 2012 1:39 PM (From:Bing Maps: Map Control and Web services Development)
    Friday, December 31, 2010 4:42 PM

Answers

  • There will be differences between the lat/long of the waypoints returned by the route service and the lat/long you supplied - assuming you chose "driving" as your mode of travel, then the routing service will return the closest points to your chosen waypoints that you can drive to via the public road network. Unless you happen to click exactly on a road, then there will always be a slight discrepancy between your "clicked" waypoints and the returned waypoints.

    As an extreme example, imagine your requested route waypoints lay in the sea, or in the middle of a desert, or on top of a mountain... you wouldn't expect the routing service to route exactly to those points, would you? The following example shows the route between 4 waypoints I arbitrarily clicked on a map of Scotland - notice how the route passes through none of the wayponts exactly?

     

    So, keep your own list of the waypoints you request (and, if you want to style them differently, then record whether they were input by mouse click or textbox) and plot them on the map from that list rather than in the waypoints returned by the route service.


    Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290
    Tuesday, January 4, 2011 9:31 AM

All replies

  • Why do you need to use the locations returned in RouteLegs at all? You already know the lat/long of each waypoint, because that's what you supplied when you requested the route in the first place. So use those same waypoint locations again to plot pushpins using whatever icon you want.

    Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290
    Monday, January 3, 2011 10:39 PM
  • The problem is I am providing waypoint functionality through mouse drag as well as using add new destination functionality(i.e. by entering address of waypoint in the textbox). I have to differentiate between waypoint added using mouse drag( show it using orange dot) & waypoint added using add new destination functionality(show custom green flag with alphabets).

     

    So from your solution I  do have lat/long of the waypoints added using mouse drag as well as lat/long of the waypoint added using add new destination functioality. If we use these lat/long to show flags on the map then will it show exactly on the same line of the route? Because there are some difference in lat/long of the points returned in the callback function with the lat/long that we have.

    Tuesday, January 4, 2011 2:34 AM
  • There will be differences between the lat/long of the waypoints returned by the route service and the lat/long you supplied - assuming you chose "driving" as your mode of travel, then the routing service will return the closest points to your chosen waypoints that you can drive to via the public road network. Unless you happen to click exactly on a road, then there will always be a slight discrepancy between your "clicked" waypoints and the returned waypoints.

    As an extreme example, imagine your requested route waypoints lay in the sea, or in the middle of a desert, or on top of a mountain... you wouldn't expect the routing service to route exactly to those points, would you? The following example shows the route between 4 waypoints I arbitrarily clicked on a map of Scotland - notice how the route passes through none of the wayponts exactly?

     

    So, keep your own list of the waypoints you request (and, if you want to style them differently, then record whether they were input by mouse click or textbox) and plot them on the map from that list rather than in the waypoints returned by the route service.


    Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290
    Tuesday, January 4, 2011 9:31 AM
  • Okay. In case of extreme example like above one the routing service won't  route exactly to own list of waypoints that we have. That's okay. It's okay to ignore such extreme case.

    So I will keep own list of waypoints and plot them on the map from that list rather than in the waypoints returned by the route service.

     

    Thanks for your solution.

    Tuesday, January 4, 2011 4:23 PM