async public void Searching()//searches for such input { bool _flag = false, _flag2 = false; if (_lon != null && _lat != null) //there's longitude and latitude entered { double _x = Double.Parse(_lat), _y = Double.Parse(_lon); //localization parsed once to double if (_x < 90 && _x > -90 && _y < 180 && _y > -180) //checks if location is within earth { AppVariables.location = new Location(); //saving this localization as a current one AppVariables.location.Latitude = _x; AppVariables.location.Longitude = _y; _flag = true; } } else if (_addr != null)//there's address entered { try { AppVariables.location = new Location(); var locations = await Geocoding.GetLocationsAsync(_addr); //looks for location AppVariables.location = locations?.FirstOrDefault(); //sets location found or sets null _flag2 = true; } catch (FeatureNotSupportedException fnsEx) { DependencyService.Get <IMessage>().LongAlert(fnsEx.Message); } } else//nothing entered just button clicked { } if (AppVariables.location != null && _flag || _flag2)//if there's location found { Trytofind trytofind = new Trytofind(); trytofind.Check(); //checks if there's already destination and calculates distance and new angle for arrow; find it in EntryPage.xaml.cs MessagingCenter.Send(this, "gobackSend"); //tell main page to swipe us back MessagingCenter.Send(this, "resetSend"); //resets input bars var newCoord = new ArchiveDatabase(); newCoord.Latitude = AppVariables.location.Latitude; //saves location to database newCoord.Longitude = AppVariables.location.Longitude; //=||= newCoord.Time = DateTime.Now.Second; //time of saving if (_flag2) { newCoord.Note = _addr; //saves inputed address as note } AppVariables.db.Insert(newCoord); //insert location to database } else { DependencyService.Get <IMessage>().LongAlert("Wrong coordinates or address");//no location found or invalid input } }
void OnSelect(object sender, EventArgs e)//triggered when cell selected { AppVariables.location = new Location(); var item = (sender as ListView).SelectedItem; AppVariables.location.Longitude = (item as Coords).longitude; AppVariables.location.Latitude = (item as Coords).latitude; MessagingCenter.Send(this, "gobackSend");//tell main page to swipe us back Trytofind trytofind = new Trytofind(); trytofind.Check();//checks if there's already destination and calculates distance and new angle for arrow; find it in EntryPage.xaml.cs }
public async void Run() { Location _position = new Location(); while (true) { var request = new GeolocationRequest(GeolocationAccuracy.High); var newposition = await Geolocation.GetLocationAsync(request);//waits for new location if (newposition != null) { AppVariables.PhoneLoc = newposition; //sends position to variables manager as it's needed later _position = newposition; MessagingCenter.Send(this, "latSend", "lat.: " + _position.Latitude.ToString()); //sends new position to show MessagingCenter.Send(this, "longSend", "long.: " + _position.Longitude.ToString()); Trytofind trytofind = new Trytofind(); trytofind.Check();//explanation below } } }