How to find optimize shortest route distance aganist multiple location in UWP bing map control

Lokender Tiwari 0 Reputation points
2023-02-03T09:57:04.3566667+00:00
Problem Statement:

Our solution:Below are the line of code we are using to depict shortest path on Map.

private async Task<bool> ShowRouteOnMap(MapControl myMap, ObservableCollection<ViewRouteDetailsUIModel> SelectedCustomerList)

        {

            var path = new List<EnhancedWaypoint>();

            path.Add(new EnhancedWaypoint(StartGeopoint, WaypointKind.Stop));

            for (int index = 0; index < SelectedCustomerList.Count; index++)

            {

                var item = SelectedCustomerList[index];

                if (!string.IsNullOrEmpty(item.Latitude) && !string.IsNullOrEmpty(item.Longitude))

                {

                    BasicGeoposition point = new BasicGeoposition() { Latitude = Convert.ToDouble(item.Latitude), Longitude = Convert.ToDouble(item.Longitude) };

                    path.Add(new EnhancedWaypoint(new Geopoint(point), WaypointKind.Via));

                }

            }

            path.Add(new EnhancedWaypoint(EndGeopoint, WaypointKind.Stop));

            MapRouteFinderResult routeResult = await MapRouteFinder.GetDrivingRouteFromEnhancedWaypointsAsync(path, new MapRouteDrivingOptions() { RouteOptimization = MapRouteOptimization.Distance });

            if (routeResult.Status == MapRouteFinderStatus.Success)

            {

                MapRouteView viewOfRoute = new MapRouteView(routeResult.Route);

                viewOfRoute.RouteColor = Colors.Blue;

                viewOfRoute.OutlineColor = Colors.Blue;

                myMap.Routes.Add(viewOfRoute);

                await myMap.TrySetViewBoundsAsync(

                routeResult.Route.BoundingBox,

                new Thickness(105),

                MapAnimationKind.Linear);

                return true;

            }

            else

            {

                await ShowNoRouteAlert();

                return false;

            }

        }

Note: Above code not helping in identifying shortest path instead it always show sequential customer's location which provided in the list.
Universal Windows Platform (UWP)
Windows Maps
Windows Maps
A Microsoft app that provides voice navigation and turn-by-turn driving, transit, and walking directions.
245 questions
{count} votes

1 answer

Sort by: Most helpful
  1. IoTGirl 2,976 Reputation points Microsoft Employee
    2023-02-09T18:32:23.4133333+00:00

    Hi Lokender,

    If a co-ordinate is not along a street and you are asking for driving directions, that co-ordinate may not be considered routable. This can also impact your ability to route. Our APIs returns both a view co-ordinate and a route co-ordinate. The view co-ordinate is what you would show as a location on a map but that can be the center of a park or large building where a vehicle could not reach. Routing to such co-ordinates are often a cause for route failures.

    If this is not the case, can you provide a small sample set of your co-ordinates that are failing?

    Sincerely, IoTGirl

    1 person found this answer helpful.
    0 comments No comments