private async void AddPlace_Click(object sender, RoutedEventArgs e)
 {
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async delegate
     {
         if (PName == string.Empty)
         {
             await new MessageDialog("Specify a name for this place").ShowAsync();
         }
         else
         {
             try
             {
                 SavedPlacesVM.AddNewPlace(new SavedPlacesVM.SavedPlaceClass()
                 {
                     Latitude  = MapView.MapControl.Center.Position.Latitude,
                     Longitude = MapView.MapControl.Center.Position.Longitude,
                     PlaceName = PNameHolder.Text
                 });
             }
             catch (Exception ex)
             {
                 await new MessageDialog(ex.Message).ShowAsync();
             }
         }
     });
 }
Esempio n. 2
0
        private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            var context = DataContext as BookmarkAddNeedsClass;

            if (DefaultName.IsChecked.Value)
            {
                try
                {
                    SavedPlacesVM.AddNewPlace(new SavedPlacesVM.SavedPlaceClass()
                    {
                        PlaceName = context.PlaceName, Latitude = context.Location.Position.Latitude, Longitude = context.Location.Position.Longitude
                    });
                    if (PinLiveTile.IsChecked.Value)
                    {
                        //var pd = await ViewModel.PlaceControls.PlaceDetailsHelper.GetPlaceDetails((DataContext as BookmarkAddNeedsClass).PlaceID);
                        Uri           square150x150Logo = new Uri("ms-appx:///Assets/Square150x150Logo.scale-100.png");
                        SecondaryTile tile = new SecondaryTile(new Random(1).Next(Int32.MaxValue).ToString(), "Home", $"{context.Location.Position.Latitude},{context.Location.Position.Longitude}", square150x150Logo, TileSize.Square150x150);
                        tile.DisplayName = PlaceNameText.Text;
                        tile.VisualElements.ShowNameOnSquare150x150Logo = true;
                        tile.VisualElements.ShowNameOnWide310x150Logo   = true;
                        tile.VisualElements.ShowNameOnSquare310x310Logo = true;
                        tile.VisualElements.Wide310x150Logo             = new Uri("ms-appx:///Assets/Wide310x150Logo.scale-200.png");
                        tile.VisualElements.Square310x310Logo           = new Uri("ms-appx:///Assets/LargeTile.scale-200.png");
                        await tile.RequestCreateAsync();
                    }
                }
                catch (Exception ex)
                {
                    await new MessageDialog(ex.Message).ShowAsync();
                    await this.ShowAsync();
                }
            }
            else
            {
                try
                {
                    SavedPlacesVM.AddNewPlace(new SavedPlacesVM.SavedPlaceClass()
                    {
                        PlaceName = PlaceNameText.Text, Latitude = context.Location.Position.Latitude, Longitude = context.Location.Position.Longitude
                    });
                    if (PinLiveTile.IsChecked.Value)
                    {
                        Uri           square150x150Logo = new Uri("ms-appx:///Assets/Square150x150Logo.scale-100.png");
                        SecondaryTile tile = new SecondaryTile(new Random(1).Next(Int32.MaxValue).ToString(), "Home", $"{context.Location.Position.Latitude},{context.Location.Position.Longitude}", square150x150Logo, TileSize.Square150x150);
                        tile.DisplayName = PlaceNameText.Text;
                        tile.VisualElements.ShowNameOnSquare150x150Logo = true;
                        tile.VisualElements.ShowNameOnWide310x150Logo   = true;
                        tile.VisualElements.ShowNameOnSquare310x310Logo = true;
                        tile.VisualElements.Wide310x150Logo             = new Uri("ms-appx:///Assets/Wide310x150Logo.scale-200.png");
                        tile.VisualElements.Square310x310Logo           = new Uri("ms-appx:///Assets/LargeTile.scale-200.png");
                        await tile.RequestCreateAsync();
                    }
                }
                catch (Exception ex)
                {
                    await new MessageDialog(ex.Message).ShowAsync();
                    await this.ShowAsync();
                }
            }
        }
Esempio n. 3
0
        async void LoadPage()
        {
            await CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async delegate
            {
                var accessStatus = await Geolocator.RequestAccessAsync();
                if (accessStatus == GeolocationAccessStatus.Allowed)
                {
                    // Subscribe to the StatusChanged event to get updates of location status changes.
                    //geolocator.StatusChanged += Geolocator_StatusChanged;
                    geolocator.PositionChanged += Geolocator_PositionChanged;
                    // Carry out the operation.
                    Geoposition pos = FastLoadGeoPosition;

                    var MyLandmarks = new List <MapElement>();

                    Geopoint snPoint = new Geopoint(new BasicGeoposition {
                        Latitude = pos.Coordinate.Point.Position.Latitude, Longitude = pos.Coordinate.Point.Position.Longitude
                    });
                    UserLocation.Location = snPoint;
                    await Task.Delay(10);
                    Map = View.MapView.MapControl;
                    //Map.MapElements.Add(UserLoction);
                    Map.Center         = snPoint;
                    Map.CenterChanged += Map_CenterChanged;
                    Map.ZoomLevel      = 16;
                    GeoLocate          = geolocator;
                    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
                        });
                    }
                    //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
                {
                    var msg = new MessageDialog("We weren't able to access your location. Please check if your device location is on and you have accepted location access to the app in privacy settings.\nHit ok button to navigate location settings and cancel to continue.");
                    msg.Commands.Add(new UICommand("OK", async delegate
                    {
                        await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-location", UriKind.RelativeOrAbsolute));
                    }));
                    msg.Commands.Add(new UICommand("Cancel", delegate { }));
                    await msg.ShowAsync();
                }
            });
        }
Esempio n. 4
0
 private async void DraggablePin_Tapped(object sender, TappedRoutedEventArgs e)
 {
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async delegate
     {
         if (ClassInitializer.GetType() == typeof(DirectionsMainUserControl))
         {
             var Pointer = (await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/InAppIcons/GMP.png")));
             if (DirectionsMainUserControl.Origin == null)
             {
                 DirectionsMainUserControl.Origin = _map.Center;
                 _map.MapElements.Add(new MapIcon()
                 {
                     Location = _map.Center,
                     NormalizedAnchorPoint = new Point(0.5, 1.0),
                     Title = "Origin",
                     Image = RandomAccessStreamReference.CreateFromFile(Pointer),
                 });
                 DirectionsMainUserControl.OriginAddress = await GeocodeHelper.GetAddress(_map.Center);
             }
             else if (DirectionsMainUserControl.Destination == null)
             {
                 DirectionsMainUserControl.Destination = _map.Center;
                 _map.MapElements.Add(new MapIcon()
                 {
                     Location = _map.Center,
                     NormalizedAnchorPoint = new Point(0.5, 1.0),
                     Title = "Destination",
                     Image = RandomAccessStreamReference.CreateFromFile(Pointer)
                 });
                 DirectionsMainUserControl.DestinationAddress = await GeocodeHelper.GetAddress(_map.Center);
             }
         }
         if (ClassInitializer.GetType() == typeof(SavedPlacesUserControl))
         {
             if (SavedPlacesUserControl.PName == string.Empty)
             {
                 await new MessageDialog("Specify a name for this place").ShowAsync();
             }
             else
             {
                 try
                 {
                     SavedPlacesVM.AddNewPlace(new SavedPlacesVM.SavedPlaceClass()
                     {
                         Latitude  = _map.Center.Position.Latitude,
                         Longitude = _map.Center.Position.Longitude,
                         PlaceName = SavedPlacesUserControl.PName
                     });
                 }
                 catch (Exception ex)
                 {
                     await new MessageDialog(ex.Message).ShowAsync();
                 }
             }
         }
     });
 }
 public async void SuggestForSearch(string searchExpression)
 {
     await AppCore.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async delegate
     {
         if (SearchResults == null)
         {
             SearchResults = new ObservableCollection <PlaceAutoComplete.Prediction>();
         }
         SearchResults.Clear();
         var saved = SavedPlacesVM.GetSavedPlaces();
         saved     = saved.Where(x => x.PlaceName.Contains(searchExpression)).ToList();
         foreach (var item in saved)
         {
             SearchResults.Add(new PlaceAutoComplete.Prediction()
             {
                 place_id = $"{item.Latitude},{item.Longitude}", description = "Saved:" + item.PlaceName
             });
         }
         if (await SettingsSetters.GetAccessToContcts())
         {
             var contacts = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly);
             if (contacts != null)
             {
                 var search = await contacts.FindContactsAsync(searchExpression);
                 var res    = search.Where(x => x.Addresses.Count > 0);
                 foreach (var item in res)
                 {
                     var cadd = item.Addresses.FirstOrDefault();
                     SearchResults.Add(new PlaceAutoComplete.Prediction()
                     {
                         description = "Contacts:" + item.Name, place_id = $"{cadd.StreetAddress}, {cadd.Locality}"
                     });
                 }
             }
         }
         if (searchExpression.Length >= 3)
         {
             var s = await PlaceAutoComplete.GetAutoCompleteResults(searchExpression, location: MapView.MapControl.Center, radius: 50000);
             if (s == null)
             {
                 return;
             }
             foreach (var item in s.predictions)
             {
                 SearchResults.Add(item);
             }
         }
     });
 }
        public async void UpdateJumpList()
        {
            try
            {
                var listjump = await JumpList.LoadCurrentAsync();

                listjump.Items.Clear();
                foreach (var Place in SavedPlacesVM.GetSavedPlaces())
                {
                    listjump.SystemGroupKind = JumpListSystemGroupKind.None;
                    listjump.Items.Add(JumpListItem.CreateWithArguments($"{Place.Latitude},{Place.Longitude}", Place.PlaceName));
                }
                await listjump.SaveAsync();
            }
            catch { }
        }
Esempio n. 7
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";
            //}
        }
Esempio n. 8
0
        private async void OriginTxt_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
        {
            var pre = args.SelectedItem as PlaceAutoComplete.Prediction;

            if (pre == null)
            {
                return;
            }
            sender.Text = pre.description;

            if (pre.description == "MyLocation")
            {
                if (sender.Name == "OriginTxt")
                {
                    var p = (await ViewModel.MapViewVM.GeoLocate.GetGeopositionAsync()).Coordinate.Point;
                    DirectionsMainUserControl.Origin = p;
                    DirectionsMainUserControl.AddPointer(p, "Origin");
                }
                else if (sender.Name == "DestTxt")
                {
                    var p = (await ViewModel.MapViewVM.GeoLocate.GetGeopositionAsync()).Coordinate.Point;
                    DirectionsMainUserControl.Destination = p;
                    DirectionsMainUserControl.AddPointer(p, "Destination");
                }
                else
                {
                    var index = sender.Name.Replace("WayPoint", string.Empty);
                    DirectionsMainUserControl.WayPoints[Convert.ToInt32(index)] = (await ViewModel.MapViewVM.GeoLocate.GetGeopositionAsync()).Coordinate.Point;
                }
            }
            else if (pre.description.StartsWith("Saved:"))
            {
                var savedplaces = SavedPlacesVM.GetSavedPlaces();
                var res         = savedplaces.Where(x => x.PlaceName == pre.description.Replace("Saved:", string.Empty)).FirstOrDefault();
                if (sender.Name == "OriginTxt")
                {
                    var p = new Geopoint(new BasicGeoposition()
                    {
                        Latitude = res.Latitude, Longitude = res.Longitude
                    });
                    DirectionsMainUserControl.Origin = p;
                    DirectionsMainUserControl.AddPointer(p, "Origin");
                }
                else if (sender.Name == "DestTxt")
                {
                    var p = new Geopoint(new BasicGeoposition()
                    {
                        Latitude = res.Latitude, Longitude = res.Longitude
                    });
                    DirectionsMainUserControl.Destination = p;
                    DirectionsMainUserControl.AddPointer(p, "Destination");
                }
                else
                {
                    var index = sender.Name.Replace("WayPoint", string.Empty);
                    DirectionsMainUserControl.WayPoints[Convert.ToInt32(index)] = new Geopoint(new BasicGeoposition()
                    {
                        Latitude = res.Latitude, Longitude = res.Longitude
                    });
                }
            }
            else
            {
                var res = await GeocodeHelper.GetInfo(pre.place_id);

                if (res == null)
                {
                    return;
                }
                var ploc = res.results.FirstOrDefault().geometry.location;
                if (sender.Name == "OriginTxt")
                {
                    var p = new Geopoint(new BasicGeoposition()
                    {
                        Latitude = ploc.lat, Longitude = ploc.lng
                    });
                    DirectionsMainUserControl.Origin = p;
                    DirectionsMainUserControl.AddPointer(p, "Origin");
                }
                else if (sender.Name == "DestTxt")
                {
                    var p = new Geopoint(new BasicGeoposition()
                    {
                        Latitude = ploc.lat, Longitude = ploc.lng
                    });
                    DirectionsMainUserControl.Destination = p;
                    DirectionsMainUserControl.AddPointer(p, "Destination");
                }
                else
                {
                    var index = sender.Name.Replace("WayPoint", string.Empty);
                    DirectionsMainUserControl.WayPoints[Convert.ToInt32(index)] = new Geopoint(new BasicGeoposition()
                    {
                        Latitude = ploc.lat, Longitude = ploc.lng
                    });
                }
            }
        }
Esempio n. 9
0
        async void LoadPage()
        {
            geolocator = GeoLocate;

            Compass = Compass.GetDefault();
            if (Compass != null)
            {
                Compass.ReadingChanged += Compass_ReadingChanged;
            }
            ActiveNavigationMode = false;
            await CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async delegate
            {
                try
                {
                    var accessStatus = await Geolocator.RequestAccessAsync();
                    if (accessStatus == GeolocationAccessStatus.Allowed)
                    {
                        if (FastLoadGeoPosition != null)
                        {
                            // Subscribe to the StatusChanged event to get updates of location status changes.
                            //geolocator.StatusChanged += Geolocator_StatusChanged;
                            geolocator.PositionChanged += Geolocator_PositionChanged;
                            // Carry out the operation.
                            var pos1 = await geolocator.GetGeopositionAsync();
                            var pos  = pos1.Coordinate.Point;

                            Geopoint snPoint = new Geopoint(new BasicGeoposition {
                                Latitude = pos.Position.Latitude, Longitude = pos.Position.Longitude
                            });
                            await Task.Delay(10);
                            Map = View.MapView.MapControl;
                            //Map.MapElements.Add(UserLoction);
                            Map.Center      = snPoint;
                            Map.ZoomLevel   = 16;
                            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);
                            UserLocation.Location = pos;
                            //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("We weren't able to access your location. Please check if your device location is on and you have accepted location access to the app in privacy settings.\nHit ok button to navigate location settings and cancel to continue.");
                        msg.Commands.Add(new UICommand("OK", async delegate
                        {
                            await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-location", UriKind.RelativeOrAbsolute));
                        }));
                        msg.Commands.Add(new UICommand("Cancel", delegate { }));
                        await msg.ShowAsync();
                    }
                }
                catch { }
            });
        }