Ejemplo n.º 1
0
        private async void geo_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
        {
            currentGeoPosition = args.Position;
            double updateDistance = 0;

            var lat = currentGeoPosition.Coordinate.Point.Position.Latitude;
            var lng = currentGeoPosition.Coordinate.Point.Position.Longitude;

            if (Util.UserProfileData.StartPlace == null)
            {
                await cd.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    await SetLocationDetails(currentGeoPosition);
                });
            }
            else
            {
                if (Util.UserProfileData.StartPlace.Latitude == -1 ||
                    Util.UserProfileData.StartPlace.Longitude == -1 ||
                    (Util.UserProfileData.StartPlace.Latitude == lat &&
                     Util.UserProfileData.StartPlace.Longitude == lng))
                {
                    updateDistance = 0;
                }
                else
                {
                    updateDistance = CalculateDistance(Util.UserProfileData.StartPlace.Latitude, Util.UserProfileData.StartPlace.Longitude, lat, lng);
                }
            }

            if (updateDistance >= 200) //>=1km
            {
                await cd.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    if (string.Compare(Util.UserProfileData.CurrentPlace.CityLocation, Util.UserProfileData.StartPlace.CityLocation, StringComparison.OrdinalIgnoreCase) != 0) //User moved to different place
                    {
                        Util.UserProfileData.HasMoved = false;
                        SampleDataSource.ClearGroups();
                        //this will trigger to load new data items, not from cache
                        NavigationHelper.NavigateToPage(typeof(UserProfile));
                        await NotificationManager.HandleErrorMessageWithToaster("City or Region location has been changed, apps data has been reset", "City location has been changed");
                    }
                    else
                    {
                        Util.UserProfileData.HasMoved = true;
                        //call our service to get type/category details for this current lat, long position, if matched add to user visting places
                        //restart timer,
                        //calculate await time or duration
                        stopWatch.Restart();
                        durationTimer.Stop();
                        durationTimer.Start();
                    }
                });
            }
        }
Ejemplo n.º 2
0
        void timer_Tick(object sender, object e)
        {
            if (!Util.IsAuthenticated())
            {
                TravAppGeoProcessor.Instance.Unsubscribe();
                WebSocketCommunicator.Instance.CloseAndDispose();
                SampleDataSource.ClearGroups();
                Util.SetUserProfile(new DataModel.UserData());

                NavigationHelper.NavigateToPage(typeof(MainPage));
            }
        }