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.