diff --git a/NavCityBreda/Helpers/Util.cs b/NavCityBreda/Helpers/Util.cs index 9d4bfac..76e3a44 100644 --- a/NavCityBreda/Helpers/Util.cs +++ b/NavCityBreda/Helpers/Util.cs @@ -4,6 +4,10 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Windows.ApplicationModel.Resources; +using Windows.Devices.Geolocation; +using Windows.Services.Maps; +using Windows.UI; +using Windows.UI.Xaml.Controls.Maps; namespace NavCityBreda.Helpers { @@ -15,5 +19,57 @@ namespace NavCityBreda.Helpers return new Windows.ApplicationModel.Resources.ResourceLoader(); } } + + public static async Task FindLocation(string location, Geopoint reference) + { + MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync(location, reference); + MapLocation from = result.Locations.First(); + return from; + } + + public static async Task FindWalkingRoute(Geopoint from, Geopoint to) + { + MapRouteFinderResult routeResult = await MapRouteFinder.GetWalkingRouteAsync(from, to); + MapRoute b = routeResult.Route; + return b; + } + + public static async Task FindWalkingRoute(string from, string to, Geopoint reference) + { + MapLocation f = await FindLocation(from, reference); + MapLocation t = await FindLocation(to, reference); + MapRoute m = await FindWalkingRoute(f.Point, t.Point); + return m; + } + + public static async Task FindDrivingRoute(Geopoint from, Geopoint to) + { + MapRouteFinderResult routeResult = await MapRouteFinder.GetDrivingRouteAsync(from, to); + MapRoute b = routeResult.Route; + return b; + } + + public static async Task FindDrivingRoute(string from, string to, Geopoint reference) + { + MapLocation f = await FindLocation(from, reference); + MapLocation t = await FindLocation(to, reference); + MapRoute m = await FindDrivingRoute(f.Point, t.Point); + return m; + } + + public static MapPolyline GetRouteLine(MapRoute m, Color color, int thickness = 10, bool dashed = false) + { + var line = new MapPolyline + { + StrokeThickness = thickness, + StrokeColor = color, + StrokeDashed = dashed, + ZIndex = 2 + }; + + line.Path = new Geopath(m.Path.Positions); + + return line; + } } }