private async void DLComplete(object sender, bool e)
        {
            if (MDH != null)
            {
                try
                {
                    MDH.DownloadCompleted -= DLComplete;
                    MDH.DownloadProgress  -= DLProgress;

                    if (MDH.FailedDownloads == 0)
                    {
                        await new MessageDialog(MultilingualHelpToolkit.GetString("MapDownloaderViewStringDLComplete", "Text")).ShowAsync();
                    }
                    else
                    {
                        await new MessageDialog(MultilingualHelpToolkit.GetString("MapDownloaderViewStringDLCompleteWithErrors", "Text").Replace("{count}", $"{MDH.FailedDownloads}")).ShowAsync();
                    }
                }
                catch { }
            }
            try
            {
                DLButton.IsEnabled = true;
            }
            catch { }
            try
            {
                new DisplayRequest().RequestRelease();
            }
            catch { }
        }
 private async void Map_MapTapped(MapControl sender, MapInputEventArgs args)
 {
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async delegate
     {
         if (fp == false)
         {
             TopLeft.Visibility = Visibility.Visible;
             TopLeftPos         = args.Location.Position;
             MapControl.SetLocation(TopLeft, args.Location);
             fp = true;
         }
         else
         {
             if (sp == false)
             {
                 BottomRight.Visibility = Visibility.Visible;
                 BottomRightPos         = args.Location.Position;
                 MapControl.SetLocation(BottomRight, args.Location);
                 sp = true;
                 DLButton.IsEnabled = true;
             }
             else
             {
                 await new MessageDialog(MultilingualHelpToolkit.GetString("MapDownloaderViewStringTwoPointsSelected", "Text")).ShowAsync();
             }
         }
     });
 }
Exemple #3
0
        public static string GetTotalEstimatedTime(Route Route)
        {
            var EstimatedTime = 0;

            foreach (var item in Route.legs)
            {
                EstimatedTime += item.duration.value;
            }
            if (Convert.ToInt32((EstimatedTime / 60)) < 60)
            {
                return($"{Convert.ToInt32((EstimatedTime / 60))} {MultilingualHelpToolkit.GetString("StringMinutes", "Text")}");
            }
            else
            {
                return($"{Convert.ToInt32(((EstimatedTime / 60) / 60))} {MultilingualHelpToolkit.GetString("StringHours", "Text")}");
            }
        }
Exemple #4
0
        public static string GetDistance(Route Route)
        {
            var Distance = 0;

            foreach (var item in Route.legs)
            {
                Distance += item.distance.value;
            }
            if (SettingsView.SettingsSetters.GetLengthUnit() == 0)
            {
                //Metric
                if (Distance <= 2000)
                {
                    return($"{Distance} {MultilingualHelpToolkit.GetString("StringMeters", "Text")}");
                }
                else
                {
                    return($"{Distance / 1000f} {MultilingualHelpToolkit.GetString("StringKiloMeters", "Text")}");
                }
            }
            else if (SettingsView.SettingsSetters.GetLengthUnit() == 1)
            {
                //Imperial
                if (Distance <= 2000)
                {
                    return($"{string.Format("{0:0.00}", Distance * 1.093613f)} {MultilingualHelpToolkit.GetString("StringYards", "Text")}");
                }
                else
                {
                    return($"{string.Format("{0:0.00}", Distance * 0.000621371f)} {MultilingualHelpToolkit.GetString("StringMiles", "Text")}");
                }
            }
            else
            {
                //US
                if (Distance <= 2000)
                {
                    return($"{string.Format("{0:0.00}", Distance * 3.28084f)} {MultilingualHelpToolkit.GetString("StringFeet", "Text")}");
                }
                else
                {
                    return($"{string.Format("{0:0.00}", Distance * 0.000621371f)} {MultilingualHelpToolkit.GetString("StringMiles", "Text")}");
                }
            }
        }
Exemple #5
0
 private async void MainPage_Loaded(object sender, RoutedEventArgs e)
 {
     Fr.Navigate(typeof(MapView), para);
     applyAcrylicAccent(MainGrid);
     HMenuTopLst.Items.Add(new MenuClass {
         Text = MultilingualHelpToolkit.GetString("StringMapView", "Text"), Icon = "", Tag = "Map View"
     });
     HMenuTopLst.Items.Add(new MenuClass {
         Text = MultilingualHelpToolkit.GetString("StringOfflineMaps", "Text"), Icon = "", Tag = "Offline Maps"
     });
     try
     {
         if (CurrentAppSimulator.LicenseInformation.IsTrial)
         {
             var exp = CurrentAppSimulator.LicenseInformation.ExpirationDate;
             if (exp.Subtract(DateTime.Now) <= new TimeSpan(4, 0, 0, 0))
             {
                 await new MessageDialog("Application will be expired on " + exp.ToString()).ShowAsync();
             }
         }
         //    HMenuBottomLst.Items.Add(new MenuClass { Text = MultilingualHelpToolkit.GetString("StringBuyFromIran", "Text"), Icon = "", Tag = "Buy from Iran" });
     }
     catch
     {
         //HMenuBottomLst.Items.Add(new MenuClass { Text = MultilingualHelpToolkit.GetString("StringBuyFromIran", "Text"), Icon = "", Tag = "Buy from Iran" });
     }
     HMenuBottomLst.Items.Add(new MenuClass {
         Text = MultilingualHelpToolkit.GetString("StringSendFeedback", "Text"), Icon = "", Tag = "Send feedback"
     });
     HMenuBottomLst.Items.Add(new MenuClass {
         Text = MultilingualHelpToolkit.GetString("StringSettings", "Text"), Icon = "", Tag = "Settings"
     });
     if (ClassInfo.DeviceType() == ClassInfo.DeviceTypeEnum.Phone)
     {
         DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait;
     }
     return;
 }
Exemple #6
0
        /// <summary>
        /// Get Directions from a Origin to a Destination
        /// </summary>
        /// <param name="Origin">The Origin BasicGeoposition</param>
        /// <param name="Destination">The Destination BasicGeoposition</param>
        /// <param name="Mode">Mode for example Driving, walking or etc.</param>
        /// <param name="WayPoints">Points you want to go in your way</param>
        /// <exception cref="ArgumentOutOfRangeException">Waypoints are not available in transit mode.</exception>
        /// <returns></returns>
        public static async Task <Rootobject> GetDirections(BasicGeoposition Origin, BasicGeoposition Destination, DirectionModes Mode = DirectionModes.driving, List <BasicGeoposition> WayPoints = null)
        {
            try
            {
                if (Mode == DirectionModes.transit && WayPoints != null)
                {
                    throw new ArgumentOutOfRangeException(MultilingualHelpToolkit.GetString("StringWayPointsNotAvailableInTransit", "Text"));
                }
                var m          = Mode.ToString();
                var requestUrl = String.Format("http://maps.google.com/maps/api/directions/json?origin=" + Origin.Latitude + "," + Origin.Longitude + "&destination=" + Destination.Latitude + "," + Destination.Longitude + "&units=metric&mode=" + Mode + "&lang=" + AppCore.GoogleMapRequestsLanguage);
                if (WayPoints != null && WayPoints.Count != 0)
                {
                    requestUrl += "&waypoints=";
                    for (int i = 0; i <= WayPoints.Count - 1; i++)
                    {
                        if (i < WayPoints.Count - 1)
                        {
                            requestUrl += $"{WayPoints[i].Latitude},{WayPoints[i].Longitude}|";
                        }
                        else
                        {
                            requestUrl += $"{WayPoints[i].Latitude},{WayPoints[i].Longitude}";
                        }
                    }
                }
                //requestUrl += $"&key={AppCore.GoogleMapAPIKey}";
                var http = new HttpClient();
                http.DefaultRequestHeaders.UserAgent.ParseAdd(AppCore.HttpUserAgent);
                var s = await http.GetStringAsync(new Uri(requestUrl, UriKind.RelativeOrAbsolute));

                return(JsonConvert.DeserializeObject <Rootobject>(s));
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemple #7
0
 private void MainPage_Loaded(object sender, RoutedEventArgs e)
 {
     Fr.Navigate(typeof(MapView), para);
     applyAcrylicAccent(MainGrid);
     HMenuTopLst.Items.Add(new MenuClass {
         Text = MultilingualHelpToolkit.GetString("StringMapView", "Text"), Icon = "", Tag = "Map View"
     });
     HMenuTopLst.Items.Add(new MenuClass {
         Text = MultilingualHelpToolkit.GetString("StringOfflineMaps", "Text"), Icon = "", Tag = "Offline Maps"
     });
     try
     {
         if (CurrentAppSimulator.LicenseInformation.IsTrial)
         {
             HMenuBottomLst.Items.Add(new MenuClass {
                 Text = MultilingualHelpToolkit.GetString("StringBuyFromIran", "Text"), Icon = "", Tag = "Buy from Iran"
             });
         }
     }
     catch
     {
         HMenuBottomLst.Items.Add(new MenuClass {
             Text = MultilingualHelpToolkit.GetString("StringBuyFromIran", "Text"), Icon = "", Tag = "Buy from Iran"
         });
     }
     HMenuBottomLst.Items.Add(new MenuClass {
         Text = MultilingualHelpToolkit.GetString("StringSendFeedback", "Text"), Icon = "", Tag = "Send feedback"
     });
     HMenuBottomLst.Items.Add(new MenuClass {
         Text = MultilingualHelpToolkit.GetString("StringSettings", "Text"), Icon = "", Tag = "Settings"
     });
     if (ClassInfo.DeviceType() == ClassInfo.DeviceTypeEnum.Phone)
     {
         DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait;
     }
     return;
 }
Exemple #8
0
 private async void MainPage_BackRequested(object sender, BackRequestedEventArgs e)
 {
     e.Handled = true;
     try
     {
         if (Fr.CanGoBack)
         {
             Fr.GoBack();
         }
         else
         {
             var msg = new MessageDialog(MultilingualHelpToolkit.GetString("stringExit", "Text"));
             msg.Commands.Add(new UICommand(MultilingualHelpToolkit.GetString("StringYes", "Text"), delegate
             {
                 App.Current.Exit();
             }));
             msg.Commands.Add(new UICommand(MultilingualHelpToolkit.GetString("StringNo", "Text"), delegate { }));
             await msg.ShowAsync();
         }
     }
     catch
     {
     }
 }
        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();
                    }
                });
            }
        }
        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();
                    }
                });
            }
        }
Exemple #11
0
        public MapViewVM()
        {
            LocationFlagVisibility       = Visibility.Visible;
            StepsTitleProviderVisibility = Visibility.Collapsed;
            if (UserLocation == null)
            {
                UserLocation = new ViewModel()
                {
                    AttractionName = "My Location"
                }
            }
            ;
            StaticVM = this;
            LoadPage();
        }

        async void LocateUser()
        {
            try
            {
                var accessStatus = await Geolocator.RequestAccessAsync();

                if (accessStatus == GeolocationAccessStatus.Allowed)
                {
                    Map = MapView.MapControl;
                    if (FastLoadGeoPosition != null)
                    {
                        if (geolocator == null)
                        {
                            geolocator = new Geolocator()
                            {
                                MovementThreshold       = 1,
                                ReportInterval          = 1,
                                DesiredAccuracyInMeters = 1
                            };
                            GeoLocate = geolocator;
                        }
                        else
                        {
                            UserLocation.Location = FastLoadGeoPosition;
                            Map.Center            = FastLoadGeoPosition;
                            await AppCore.Dispatcher.RunAsync(CoreDispatcherPriority.High, async delegate
                            {
                                await Map.TryZoomToAsync(16);
                            });
                        }
                        // Subscribe to the StatusChanged event to get updates of location status changes.
                        //geolocator.StatusChanged += Geolocator_StatusChanged;
                        // Carry out the operation.
                        GeoLocatorHelper.GetUserLocation();
                        GeoLocatorHelper.LocationFetched += GeoLocatorHelper_LocationFetched;
                        geolocator.PositionChanged       += Geolocator_PositionChanged;
                        await AppCore.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, delegate
                        {
                            var savedplaces = SavedPlacesVM.GetSavedPlaces();
                            foreach (var item in savedplaces)
                            {
                                Map.MapElements.Add(new MapIcon()
                                {
                                    Location = new Geopoint(new BasicGeoposition()
                                    {
                                        Latitude = item.Latitude, Longitude = item.Longitude
                                    }),
                                    Title = item.PlaceName
                                });
                            }
                        });

                        await Task.Delay(150);

                        LocationFlagVisibility = Visibility.Visible;
                        //if (Map.Is3DSupported)
                        //{
                        //    Map.Style = MapStyle.Aerial3DWithRoads;
                        //    MapScene mapScene = MapScene.CreateFromLocationAndRadius(snPoint, 500, 150, 70);
                        //    await Map.TrySetSceneAsync(mapScene);
                        //}
                        //var r = await MapLocationFinder.FindLocationsAtAsync(snPoint);
                        //if(r.Locations != null)
                        //{
                        //    var re = r.Locations.FirstOrDefault();
                        //    var rg = RegionInfo.CurrentRegion;
                        //    var rg2 = new RegionInfo(re.Address.Country);
                        //}
                    }
                    else
                    {
                        LocationFlagVisibility = Visibility.Collapsed;
                    }
                }
                else
                {
                    LocationFlagVisibility = Visibility.Collapsed;
                    var msg = new MessageDialog(MultilingualHelpToolkit.GetString("StringLocationPrivacy", "Text"));
                    msg.Commands.Add(new UICommand(MultilingualHelpToolkit.GetString("StringOK", "Text"), async delegate
                    {
                        await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-location", UriKind.RelativeOrAbsolute));
                    }));
                    msg.Commands.Add(new UICommand(MultilingualHelpToolkit.GetString("StringCancel", "Text"), delegate { }));
                    await msg.ShowAsync();

                    Window.Current.Activated += Current_Activated;
                }
            }
            catch { }
            //try
            //{
            //    ApplicationData.Current.LocalSettings.Values["WCReponse"].ToString();
            //}
            //catch
            //{
            //    var message = new MessageDialog("windowscentral is not a Microsoft News website that you are looking for. See our reply to WindowsCentral post about WinGo Maps.");
            //    message.Commands.Add(new UICommand("See our response on twitter.", async delegate
            //    {
            //        await Launcher.LaunchUriAsync(new Uri("https://twitter.com/NGameAli/status/1028157663752978432"));
            //    }));
            //    await message.ShowAsync();
            //    ApplicationData.Current.LocalSettings.Values["WCReponse"] = "windowscentral is not a Microsoft News website that you are looking for";
            //}
        }