async private void inputFiled_ActionIconTapped(object sender, System.EventArgs e) { btnNext.Visibility = System.Windows.Visibility.Collapsed; progressBar.Visibility = System.Windows.Visibility.Visible; App.ViewModel.UserViewModel.AllowGPS = true; var gps = new GPSHelper(); var result = await gps.GetPositionAsync(); if (result != null) { int zipHelper = 0; var zip = await bingHelper.GeoCoordinateToZipCodeAsync(result.Latitude, result.Longitude); inputFiled.Text = zip; App.ViewModel.UserViewModel.Location = new Location() { IsGeoCoded = true, IsValid = true, Latitude = result.Latitude, Longitude = result.Longitude, Accuracy = 0, ZipCode = int.TryParse(zip, out zipHelper) ? zipHelper : 0 }; inputFiled.SelectionStart = inputFiled.Text.Length; PostnummerServiceHelper post = new PostnummerServiceHelper(); var r = await post.GeoToPostalCode(result.Latitude, result.Longitude); string p = r; } progressBar.Visibility = System.Windows.Visibility.Collapsed; btnNext.Visibility = System.Windows.Visibility.Visible; }
private void MaintainGpsLocation() { if (IsMaintainGpsLocationRunning) { return; } GPSHelper gps = new GPSHelper(); var lastLocation = new GeoCoordinate(UserViewModel.Location.Latitude, UserViewModel.Location.Longitude); TaskEx.Run(async() => { IsMaintainGpsLocationRunning = true; while (UserViewModel.AllowGPS) { var location = await gps.GetPositionAsync(); if (location != null && !location.IsUnknown) { Deployment.Current.Dispatcher.BeginInvoke(() => { UserViewModel.Location.Latitude = location.Latitude; UserViewModel.Location.Longitude = location.Longitude; UserViewModel.Location.IsGeoCoded = false; UserViewModel.Location.Timestamp = DateTime.Now.Ticks; if (location.GetDistanceTo(lastLocation) > 300) { lastLocation = new GeoCoordinate(UserViewModel.Location.Latitude, UserViewModel.Location.Longitude); UpdateViewModel(); } }); } Thread.Sleep(TimeSpan.FromSeconds(10)); } IsMaintainGpsLocationRunning = false; }); }
private async void InitializeGPS() { if (App.ViewModel.UserViewModel.AllowGPS) { var gps = new GPSHelper(); var result = await gps.GetPositionAsync(); if (result != null) { App.ViewModel.UserViewModel.Location = new Location() { IsGeoCoded = true, IsValid = true, Latitude = result.Latitude, Longitude = result.Longitude }; } } }