Exemplo n.º 1
0
 private async void Button_Click(object sender, RoutedEventArgs e)
 {
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async delegate
     {
         if (DirectionsMainUserControl.Origin != null && DirectionsMainUserControl.Destination != null)
         {
             var Origin      = DirectionsMainUserControl.Origin;
             var Destination = DirectionsMainUserControl.Destination;
             var r           = await DirectionsHelper.GetDirections(Origin.Position, Destination.Position, DirectionsHelper.DirectionModes.transit);
             if (r == null || r.routes.Count() == 0)
             {
                 await new MessageDialog("No way to your destination!!!").ShowAsync();
                 return;
             }
             var route = DirectionsHelper.GetDirectionAsRoute(r.routes.FirstOrDefault(), Colors.Purple);
             MapView.MapControl.MapElements.Add(route);
             var es = DirectionsHelper.GetTotalEstimatedTime(r.routes.FirstOrDefault());
             var di = DirectionsHelper.GetDistance(r.routes.FirstOrDefault());
             await new MessageDialog($"we calculate that the route is about {di} and takes about {es}").ShowAsync();
             MapView.MapControl.ZoomLevel = 18;
             MapView.MapControl.Center    = DirectionsMainUserControl.Origin;
         }
         else
         {
             await new MessageDialog("You didn't select both origin and destination points").ShowAsync();
         }
     });
 }
Exemplo n.º 2
0
        public async void DirectionFinder()
        {
            if (Destination == null)
            {
                return;
            }
            await VoiceHelper.ReadText("calculating route");

            MapPolyline CurrentDrawed = null;

            try
            {
                foreach (var item in MapView.MapControl.MapElements)
                {
                    if (item.GetType() == typeof(MapPolyline))
                    {
                        CurrentDrawed = (MapPolyline)item;
                    }
                }
            }
            catch { }
            if (Mode == DirectionMode.walking)
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async delegate
                {
                    try
                    {
                        if (Origin != null && Destination != null)
                        {
                            DirectionsHelper.Rootobject r = null;
                            if (Waypoints == null)
                            {
                                r = await DirectionsHelper.GetDirections(Origin.Position, Destination.Position, DirectionsHelper.DirectionModes.walking);
                            }
                            else
                            {
                                var lst = new List <BasicGeoposition>();
                                foreach (var item in Waypoints)
                                {
                                    if (item != null)
                                    {
                                        lst.Add(new BasicGeoposition()
                                        {
                                            Latitude = item.Position.Latitude, Longitude = item.Position.Longitude
                                        });
                                    }
                                }
                                if (lst.Count > 0)
                                {
                                    r = await DirectionsHelper.GetDirections(Origin.Position, Destination.Position, DirectionsHelper.DirectionModes.walking, lst);
                                }
                                else
                                {
                                    r = await DirectionsHelper.GetDirections(Origin.Position, Destination.Position, DirectionsHelper.DirectionModes.walking);
                                }
                            }
                            if (r == null || r.routes.Count() == 0)
                            {
                                await new MessageDialog(MultilingualHelpToolkit.GetString("StringNoWayToDestination", "Text")).ShowAsync();
                                return;
                            }
                            if (CurrentDrawed != null)
                            {
                                MapView.MapControl.MapElements.Remove(CurrentDrawed);
                            }
                            var route = DirectionsHelper.GetDirectionAsRoute(r.routes.FirstOrDefault(), (Color)Resources["SystemControlBackgroundAccentBrush"]);
                            MapView.MapControl.MapElements.Add(route);
                            var es = DirectionsHelper.GetTotalEstimatedTime(r.routes.FirstOrDefault());
                            var di = DirectionsHelper.GetDistance(r.routes.FirstOrDefault());
                            await new MessageDialog($"{MultilingualHelpToolkit.GetString("StringDirectionCalculated", "Text")}".Replace("{di}", di).Replace("{es}", es)).ShowAsync();
                            //await new MessageDialog($"we calculate that the route is about {di} and takes about {es}").ShowAsync();
                            await MapView.MapControl.TryZoomToAsync(16);
                            MapView.MapControl.Center       = Origin;
                            MapView.MapControl.DesiredPitch = 45;
                            MapViewVM.ActiveNavigationMode  = true;
                            new DisplayRequest().RequestActive();
                        }
                        else
                        {
                            await new MessageDialog(MultilingualHelpToolkit.GetString("StringSelectBothOriginAndDestination", "Text")).ShowAsync();
                        }
                    }
                    catch (Exception ex)
                    {
                        //await new MessageDialog("error on DirectionFinder in Walking Mode" + Environment.NewLine + ex.Message).ShowAsync();
                    }
                });
            }
            else if (Mode == DirectionMode.driving)
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async delegate
                {
                    try
                    {
                        if (Origin != null && Destination != null)
                        {
                            DirectionsHelper.Rootobject r = null;
                            if (Waypoints == null)
                            {
                                r = await DirectionsHelper.GetDirections(Origin.Position, Destination.Position, DirectionsHelper.DirectionModes.driving);
                            }
                            else
                            {
                                var lst = new List <BasicGeoposition>();
                                foreach (var item in Waypoints)
                                {
                                    if (item != null)
                                    {
                                        lst.Add(new BasicGeoposition()
                                        {
                                            Latitude = item.Position.Latitude, Longitude = item.Position.Longitude
                                        });
                                    }
                                }
                                if (lst.Count > 0)
                                {
                                    r = await DirectionsHelper.GetDirections(Origin.Position, Destination.Position, DirectionsHelper.DirectionModes.driving, lst);
                                }
                                else
                                {
                                    r = await DirectionsHelper.GetDirections(Origin.Position, Destination.Position, DirectionsHelper.DirectionModes.driving);
                                }
                            }
                            if (r == null || r.routes.Count() == 0)
                            {
                                await new MessageDialog(MultilingualHelpToolkit.GetString("StringNoWayToDestination", "Text")).ShowAsync();
                                return;
                            }
                            if (CurrentDrawed != null)
                            {
                                MapView.MapControl.MapElements.Remove(CurrentDrawed);
                            }
                            var route = DirectionsHelper.GetDirectionAsRoute(r.routes.FirstOrDefault(), (Color)Resources["SystemControlBackgroundAccentBrush"]);
                            MapView.MapControl.MapElements.Add(route);
                            var es = DirectionsHelper.GetTotalEstimatedTime(r.routes.FirstOrDefault());
                            var di = DirectionsHelper.GetDistance(r.routes.FirstOrDefault());
                            await new MessageDialog($"{MultilingualHelpToolkit.GetString("StringDirectionCalculated", "Text")}".Replace("{di}", di).Replace("{es}", es)).ShowAsync();
                            await MapView.MapControl.TryZoomToAsync(16);
                            MapView.MapControl.Center       = Origin;
                            MapView.MapControl.DesiredPitch = 45;
                            MapViewVM.ActiveNavigationMode  = true;
                            new DisplayRequest().RequestActive();
                        }
                        else
                        {
                            await new MessageDialog(MultilingualHelpToolkit.GetString("StringSelectBothOriginAndDestination", "Text")).ShowAsync();
                        }
                    }
                    catch (Exception ex)
                    {
                        //await new MessageDialog("error on DirectionFinder in Driving Mode" + Environment.NewLine + ex.Message).ShowAsync();
                    }
                });
            }
            else
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async delegate
                {
                    try
                    {
                        if (Origin != null && Destination != null)
                        {
                            DirectionsHelper.Rootobject r = null;
                            r = await DirectionsHelper.GetDirections(Origin.Position, Destination.Position, DirectionsHelper.DirectionModes.transit);
                            if (r == null || r.routes.Count() == 0)
                            {
                                await new MessageDialog(MultilingualHelpToolkit.GetString("StringNoWayToDestination", "Text")).ShowAsync();
                                return;
                            }
                            if (CurrentDrawed != null)
                            {
                                MapView.MapControl.MapElements.Remove(CurrentDrawed);
                            }
                            var route = DirectionsHelper.GetDirectionAsRoute(r.routes.FirstOrDefault(), (Color)Resources["SystemControlBackgroundAccentBrush"]);
                            MapView.MapControl.MapElements.Add(route);
                            var es = DirectionsHelper.GetTotalEstimatedTime(r.routes.FirstOrDefault());
                            var di = DirectionsHelper.GetDistance(r.routes.FirstOrDefault());
                            foreach (var item in r.routes.FirstOrDefault().legs)
                            {
                                foreach (var item2 in item.steps)
                                {
                                    if (item2.transit_details != null)
                                    {
                                        var ico = RandomAccessStreamReference.CreateFromUri(new Uri("http:" + item2.transit_details.line.vehicle.icon));
                                        MapView.MapControl.MapElements.Add(new MapIcon()
                                        {
                                            Image = ico, Title = "arrival " + item2.transit_details.headsign, Location = new Geopoint(new BasicGeoposition()
                                            {
                                                Latitude = item2.transit_details.arrival_stop.location.lat, Longitude = item2.transit_details.arrival_stop.location.lng
                                            })
                                        });
                                        MapView.MapControl.MapElements.Add(new MapIcon()
                                        {
                                            Image = ico, Title = "departure  " + item2.transit_details.headsign, Location = new Geopoint(new BasicGeoposition()
                                            {
                                                Latitude = item2.transit_details.departure_stop.location.lat, Longitude = item2.transit_details.departure_stop.location.lng
                                            })
                                        });
                                    }
                                }
                            }
                            await new MessageDialog($"{MultilingualHelpToolkit.GetString("StringDirectionCalculated", "Text")}".Replace("{di}", di).Replace("{es}", es)).ShowAsync();
                            await MapView.MapControl.TryZoomToAsync(16);
                            MapView.MapControl.Center       = Origin;
                            MapView.MapControl.DesiredPitch = 45;
                            MapViewVM.ActiveNavigationMode  = true;
                            new DisplayRequest().RequestActive();
                        }
                        else
                        {
                            await new MessageDialog(MultilingualHelpToolkit.GetString("StringSelectBothOriginAndDestination", "Text")).ShowAsync();
                        }
                    }
                    catch (Exception ex)
                    {
                        //await new MessageDialog("error on DirectionFinder in Transit Mode" + Environment.NewLine + ex.Message).ShowAsync();
                    }
                });
            }
        }
Exemplo n.º 3
0
        public async Task DirectionFinderAsync()
        {
            MapPolyline CurrentDrawed = null;

            try
            {
                foreach (var item in MapView.MapControl.MapElements)
                {
                    if (item.GetType() == typeof(MapPolyline))
                    {
                        CurrentDrawed = (MapPolyline)item;
                    }
                }
            }
            catch { }
            if (Mode == DirectionMode.walking)
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async delegate
                {
                    if (Origin != null && Destination != null)
                    {
                        DirectionsHelper.Rootobject r = null;
                        if (Waypoints == null)
                        {
                            r = await DirectionsHelper.GetDirections(Origin.Position, Destination.Position, DirectionsHelper.DirectionModes.walking);
                        }
                        else
                        {
                            var lst = new List <BasicGeoposition>();
                            foreach (var item in Waypoints)
                            {
                                if (item != null)
                                {
                                    lst.Add(new BasicGeoposition()
                                    {
                                        Latitude = item.Position.Latitude, Longitude = item.Position.Longitude
                                    });
                                }
                            }
                            if (lst.Count > 0)
                            {
                                r = await DirectionsHelper.GetDirections(Origin.Position, Destination.Position, DirectionsHelper.DirectionModes.walking, lst);
                            }
                            else
                            {
                                r = await DirectionsHelper.GetDirections(Origin.Position, Destination.Position, DirectionsHelper.DirectionModes.walking);
                            }
                        }
                        if (r == null || r.routes.Count() == 0)
                        {
                            //await new MessageDialog("No way to your destination!!!").ShowAsync();
                            return;
                        }
                        if (CurrentDrawed != null)
                        {
                            MapView.MapControl.MapElements.Remove(CurrentDrawed);
                        }
                        var route = DirectionsHelper.GetDirectionAsRoute(r.routes.FirstOrDefault(), (Color)Resources["SystemControlBackgroundAccentBrush"]);
                        MapView.MapControl.MapElements.Add(route);
                        var es = DirectionsHelper.GetTotalEstimatedTime(r.routes.FirstOrDefault());
                        var di = DirectionsHelper.GetDistance(r.routes.FirstOrDefault());
                        //await new MessageDialog($"we calculate that the route is about {di} and takes about {es}").ShowAsync();
                        await MapView.MapControl.TryZoomToAsync(16);
                        MapView.MapControl.Center       = Origin;
                        MapView.MapControl.DesiredPitch = 45;
                        MapViewVM.ActiveNavigationMode  = true;
                        new DisplayRequest().RequestActive();
                    }
                    else
                    {
                        await new MessageDialog(MultilingualHelpToolkit.GetString("StringSelectBothOriginAndDestination", "Text")).ShowAsync();
                    }
                });
            }
            else if (Mode == DirectionMode.driving)
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async delegate
                {
                    if (Origin != null && Destination != null)
                    {
                        DirectionsHelper.Rootobject r = null;
                        if (Waypoints == null)
                        {
                            r = await DirectionsHelper.GetDirections(Origin.Position, Destination.Position, DirectionsHelper.DirectionModes.driving);
                        }
                        else
                        {
                            var lst = new List <BasicGeoposition>();
                            foreach (var item in Waypoints)
                            {
                                if (item != null)
                                {
                                    lst.Add(new BasicGeoposition()
                                    {
                                        Latitude = item.Position.Latitude, Longitude = item.Position.Longitude
                                    });
                                }
                            }
                            if (lst.Count > 0)
                            {
                                r = await DirectionsHelper.GetDirections(Origin.Position, Destination.Position, DirectionsHelper.DirectionModes.driving, lst);
                            }
                            else
                            {
                                r = await DirectionsHelper.GetDirections(Origin.Position, Destination.Position, DirectionsHelper.DirectionModes.driving);
                            }
                        }
                        if (r == null || r.routes.Count() == 0)
                        {
                            //await new MessageDialog("No way to your destination!!!").ShowAsync();
                            return;
                        }
                        if (CurrentDrawed != null)
                        {
                            MapView.MapControl.MapElements.Remove(CurrentDrawed);
                        }
                        var route = DirectionsHelper.GetDirectionAsRoute(r.routes.FirstOrDefault(), (Color)Resources["SystemControlBackgroundAccentBrush"]);
                        MapView.MapControl.MapElements.Add(route);
                        var es = DirectionsHelper.GetTotalEstimatedTime(r.routes.FirstOrDefault());
                        var di = DirectionsHelper.GetDistance(r.routes.FirstOrDefault());
                        //await new MessageDialog($"we calculate that the route is about {di} and takes about {es}").ShowAsync();
                        await MapView.MapControl.TryZoomToAsync(16);
                        MapView.MapControl.Center       = Origin;
                        MapView.MapControl.DesiredPitch = 45;
                        MapViewVM.ActiveNavigationMode  = true;
                        new DisplayRequest().RequestActive();
                    }
                    else
                    {
                        await new MessageDialog(MultilingualHelpToolkit.GetString("StringSelectBothOriginAndDestination", "Text")).ShowAsync();
                    }
                });
            }
            else
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async delegate
                {
                    if (Origin != null && Destination != null)
                    {
                        DirectionsHelper.Rootobject r = null;
                        r = await DirectionsHelper.GetDirections(Origin.Position, Destination.Position, DirectionsHelper.DirectionModes.transit);
                        if (r == null || r.routes.Count() == 0)
                        {
                            //await new MessageDialog("No way to your destination!!!").ShowAsync();
                            return;
                        }
                        if (CurrentDrawed != null)
                        {
                            MapView.MapControl.MapElements.Remove(CurrentDrawed);
                        }
                        var route = DirectionsHelper.GetDirectionAsRoute(r.routes.FirstOrDefault(), (Color)Resources["SystemControlBackgroundAccentBrush"]);
                        MapView.MapControl.MapElements.Add(route);
                        var es = DirectionsHelper.GetTotalEstimatedTime(r.routes.FirstOrDefault());
                        var di = DirectionsHelper.GetDistance(r.routes.FirstOrDefault());
                        //await new MessageDialog($"we calculate that the route is about {di} and takes about {es}").ShowAsync();
                        await MapView.MapControl.TryZoomToAsync(16);
                        MapView.MapControl.Center       = Origin;
                        MapView.MapControl.DesiredPitch = 45;
                        MapViewVM.ActiveNavigationMode  = true;
                        new DisplayRequest().RequestActive();
                    }
                    else
                    {
                        await new MessageDialog(MultilingualHelpToolkit.GetString("StringSelectBothOriginAndDestination", "Text")).ShowAsync();
                    }
                });
            }
        }
Exemplo n.º 4
0
 private async void Button_Click(object sender, RoutedEventArgs e)
 {
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async delegate
     {
         if (DirectionsMainUserControl.Origin != null && DirectionsMainUserControl.Destination != null)
         {
             var Origin      = DirectionsMainUserControl.Origin;
             var Destination = DirectionsMainUserControl.Destination;
             DirectionsHelper.Rootobject r = null;
             if (DirectionsMainUserControl.WayPoints == null)
             {
                 r = await DirectionsHelper.GetDirections(Origin.Position, Destination.Position, DirectionsHelper.DirectionModes.walking);
             }
             else
             {
                 var lst = new List <BasicGeoposition>();
                 foreach (var item in DirectionsMainUserControl.WayPoints)
                 {
                     if (item != null)
                     {
                         lst.Add(new BasicGeoposition()
                         {
                             Latitude = item.Position.Latitude, Longitude = item.Position.Longitude
                         });
                     }
                 }
                 if (lst.Count > 0)
                 {
                     r = await DirectionsHelper.GetDirections(Origin.Position, Destination.Position, DirectionsHelper.DirectionModes.walking, lst);
                 }
                 else
                 {
                     r = await DirectionsHelper.GetDirections(Origin.Position, Destination.Position, DirectionsHelper.DirectionModes.walking);
                 }
             }
             if (r == null || r.routes.Count() == 0)
             {
                 await new MessageDialog("No way to your destination!!!").ShowAsync();
                 return;
             }
             var route = DirectionsHelper.GetDirectionAsRoute(r.routes.FirstOrDefault(), (Color)Resources["SystemControlBackgroundAccentBrush"]);
             try
             {
                 foreach (var item in MapView.MapControl.MapElements)
                 {
                     if (item.GetType() == typeof(MapPolyline))
                     {
                         MapView.MapControl.MapElements.Remove(item);
                     }
                 }
             }
             catch { }
             MapView.MapControl.MapElements.Add(route);
             var es = DirectionsHelper.GetTotalEstimatedTime(r.routes.FirstOrDefault());
             var di = DirectionsHelper.GetDistance(r.routes.FirstOrDefault());
             await new MessageDialog($"we calculate that the route is about {di} and takes about {es}").ShowAsync();
             MapView.MapControl.ZoomLevel = 18;
             MapView.MapControl.Center    = DirectionsMainUserControl.Origin;
         }
         else
         {
             await new MessageDialog("You didn't select both origin and destination points").ShowAsync();
         }
     });
 }