Esempio n. 1
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();
                }
            });
        }
 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. 4
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. 5
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. 6
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 { }
            });
        }