private bool OnTimerTick() { Task.Run(async() => { Items.Clear(); Items = await RefreshDataAsync(); PinCollection.Clear(); if (SelectedBus != null) { var qw = Items.Where(n => n.BusNumber == SelectedBus); foreach (var item in qw) { PinCollection.Add(new Pin() { Position = new Position(item.Latitude, item.Longitude), Type = PinType.Generic, Label = item.BusNumber }); } } else { foreach (var item in Items) { PinCollection.Add(new Pin() { Position = new Position(item.Latitude, item.Longitude), Type = PinType.Generic, Label = item.BusNumber }); } } }); return(true); }
async Task GetCurrentLocation() { if (UserSettings.UseGPS == "True") { try { var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location); var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 20; var position = await locator.GetPositionAsync(timeout : TimeSpan.FromMilliseconds(10000)); CurrentPosition = position; var loc = new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude); PinCollection.Add(new Pin { Position = loc, Type = PinType.Generic, Label = "You are Here!" }); DisplayMessage = $"You are at {position.Latitude} Latitude and {position.Longitude} Longitude"; } catch (Exception ex) { DisplayMessage = ex.Message.ToString(); } } else { DisplayMessage = "GPS is Disabled"; } }
protected override async void OnAppearing() { base.OnAppearing(); try { var position = await Utilities.GetCurrentGeolocationAsync(); MyPosition = new Position(position.Latitude, position.Longitude); PinCollection.Add(new CustomPin() { Id = "Ryan", Position = MyPosition, Label = "Ryan", Type = PinType.Generic, Url = "http://www.ryanrauch.com/" }); PolygonCollection.Add(new Position(30.39983, -97.723719)); PolygonCollection.Add(new Position(30.40182, -97.722989)); PolygonCollection.Add(new Position(30.402172, -97.724245)); PolygonCollection.Add(new Position(30.403236, -97.72374)); PolygonCollection.Add(new Position(30.402606, -97.721659)); PolygonCollection.Add(new Position(30.399562, -97.723011)); //UpdateMapGrid(); //UpdateLocation(); //UpdatePolygons(); //MapContent.PropertyChanged += MapContent_PropertyChanged; //this has not worked yet, but used to change grids when zoomed by user //UpdateRestService(); } catch (Exception ex) { await DisplayAlert(ex.Message, ex.StackTrace, "OK"); } }
public MapViewModel() { Navigation NavPag = new Navigation(); Task.Run(async() => { var position = await CrossGeolocator.Current.GetPositionAsync(); MyPosition = new Position(position.Latitude, position.Longitude); var db = new SQLiteConnection(App.DatabaseLocation); var testList = db.Table <Parking>().ToList(); foreach (Parking parkingPosition in testList) { PinCollection.Add(new CustomPin() { Position = new Position(parkingPosition.Latitude, parkingPosition.Longitude), Type = PinType.SearchResult, Label = parkingPosition.Name }); } }); }
public LocationViewModel() { Services.APIDataStore API = new Services.APIDataStore(); foreach (ParkingMeter meter in API.meters) { Position position = new Position(Double.Parse(meter.LATITUDE), Double.Parse(meter.LONGITUDE)); string pinLabel = "Meter " + meter.METER_NO + ", Available Bays: " + meter.VEH_BAYS; PinCollection.Add(new Pin() { Position = position, Type = PinType.Generic, Label = pinLabel }); } Device.BeginInvokeOnMainThread(async() => { try { GeolocationRequest request = new GeolocationRequest(GeolocationAccuracy.Medium); // change accuracy if needed var location = await Geolocation.GetLocationAsync(request); if (location != null) { UserPosition = new Position(location.Latitude, location.Longitude); } } catch (Exception ex) { Device.BeginInvokeOnMainThread(async() => { await App.Current.MainPage.DisplayAlert("Something's gone wrong", "There has been an error in getting your location. " + ex.Message, "OK"); }); } }); }
public async override void OnNavigatedTo(INavigationParameters parameters) { base.OnNavigatedTo(parameters); ComplaintModelObj = _complaintService.GetNonComplaint(); try { if (_settings.IsOnline == true) { if (string.IsNullOrEmpty(ComplaintModelObj.GpsLocations)) { IsBusy = true; var position = await Plugin.Geolocator.CrossGeolocator.Current.GetPositionAsync(); var placemarks = await Geocoding.GetPlacemarksAsync(position.Latitude, position.Longitude); var placemark = placemarks?.FirstOrDefault(); string Locationstring = ""; if (placemark != null) { Locationstring = $"{placemark.SubAdminArea} {placemark.AdminArea}, { placemark.SubLocality} {placemark.Locality} , {placemark.PostalCode} {placemark.CountryName}"; } MyPosition = new Position(position.Latitude, position.Longitude); //PinCollection.Add(new Pin() { Position = MyPosition, Type = PinType.Generic/*, Label = "Location", Address = string.IsNullOrEmpty(Locationstring) ? null : Locationstring */,Effects }); PinCollection.Add(new Pin() { Position = MyPosition, Type = PinType.Generic, Label = "Slaughter House Location" }); IsBusy = false; } else { string[] locationsplict = ComplaintModelObj.GpsLocations.Split(','); MyPosition = new Position(Convert.ToDouble(locationsplict[0]), Convert.ToDouble(locationsplict[1])); //PinCollection.Add(new Pin() { Position = MyPosition, Type = PinType.Generic/*, Label = "Location", Address = string.IsNullOrEmpty(Locationstring) ? null : Locationstring */,Effects }); PinCollection.Add(new Pin() { Position = MyPosition, Type = PinType.Generic, Label = "Slaughter House Location" }); IsBusy = false; } } else { IsEmpty = true; IsBusy = false; EmptyStateTitle = AppAlertMessage.NoInternetConnections; } } catch (Exception ex) { await PageDialogService.DisplayAlertAsync(null, AppAlertMessage.TechnicalError, "OK"); IsBusy = false; } }
private void UpdateMap(double latitude, double longitude) { PinCollection.Clear(); MyPosition = new Xamarin.Forms.Maps.Position(latitude, longitude); PinCollection.Add(new Pin() { Position = MyPosition, Type = PinType.Generic, Label = _selectedAsar.AsarName }); }
//private void PolygonCollection_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) //{ // OnPropertyChanged("PolygonCollection"); //} public async void UpdateLocation() { var position = await Utilities.GetCurrentGeolocationAsync(); MyPosition = new Position(position.Latitude, position.Longitude); PinCollection.Add(new Pin() { Position = MyPosition, Label = "Ryan", Type = PinType.Generic }); }
public MainViewModel() { PinCollection.Add(new Pin() { Position = MyPosition, Type = PinType.Generic, Label = "I'm a Pin" }); Task.Run(async() => { var position = await Plugin.Geolocator.CrossGeolocator.Current.GetPositionAsync(); MyPosition = new Position(position.Latitude, position.Longitude); }); }
internal void UpdateMapPins() { PinCollection.Clear(); foreach (var f in FugitiveCollection) { PinCollection.Add(new ColouredMapPin() { Position = f.Position, Label = f.Username, Type = PinType.Generic, Colour = f.Colour }); } }
private async Task PinLocationsAsync() //plaats pins { await Task.Run(() => { foreach (Location pinnedLocation in currentLocationGroup.LocationItems) { MyPosition = new Position(pinnedLocation.Latitude, pinnedLocation.Longitude); PinLabel = $"{pinnedLocation.LocationName} op {pinnedLocation.TimeLocation.ToString(" d MMMM yyyy HH:mm:ss uur", CultureInfo.CurrentCulture)}"; PinCollection.Add(new Pin() { Position = MyPosition, Type = PinType.Generic, Label = PinLabel }); } }); }
public MapViewModel(BindableMap myMap) { System.Threading.Tasks.Task.Run(async() => { position = await Plugin.Geolocator.CrossGeolocator.Current.GetPositionAsync(); MyPosition = new Position(position.Latitude, position.Longitude); //_myPosition = new Position(position.Latitude, position.Longitude); //BindableMap MapPositionProperty = new BindableMap(); //MapPositionProperty.MapPosition = MyPosition; PinCollection.Add(new Pin() { Position = MyPosition, Type = PinType.Generic, Label = "I'm a Pin" }); }); /* * System.Threading.Tasks.Task.Run(async () => * { * while (position == null) * { * Thread.Sleep(1); * } * * Polyline polyline = new Polyline * { * StrokeColor = Color.Red, * StrokeWidth = 15, * Geopath = * { * new Position(MyPosition.Latitude, MyPosition.Longitude), * //new Position(53, 50) * new Position(53.213383, 50.176535), * new Position(53.212969, 50.1775006), * new Position(53.212502, 50.178328), * * new Position(53.212336, 50.177048), * new Position(53.213673, 50.176805) * //new Position(position.Latitude, position.Longitude) * // new Position(position.Latitude, position.Longitude) * * } * }; * myMap.MapElements.Add(polyline); * * }); */ }
//---------------- public MainViewModel() { Items = new List <BusPins>(); Task.Run(async() => { Items = await RefreshDataAsync(); foreach (var item in Items) { PinCollection.Add(new Pin() { Position = new Position(item.Latitude, item.Longitude), Type = PinType.Generic, Label = item.BusNumber }); } Numbers.Sort(); BusNumbers = new ObservableCollection <string>(Numbers); }); Device.StartTimer(TimeSpan.FromSeconds(5), OnTimerTick); }
public RouteStopViewModel() { Title = "Route Stops"; RouteStops = new ObservableRangeCollection <RouteStop>(); RouteStops.CollectionChanged += (sender, args) => { Debug.WriteLine("Item {args.Action}"); }; GetRouteStopsCommand = new Command(async() => await GetRouteStopsAsync()); GetClosestCommand = new Command(async() => await GetClosestAsync()); var pin = new CustomPin { Position = new Position(41.411835, -75.665245), Type = PinType.Place, Label = "The Office", Address = "Scranton PA", Id = "Xamarin2", Url = "http://xamarin.com/about/" }; PinCollection.Add(new CustomPin() { Position = MyPosition, Type = PinType.Place, Label = "Xamarin San Francisco Office", Address = "394 Pacific Ave, San Francisco CA", Id = "Xamarin", Url = "http://xamarin.com/about/" }); //PinCollection.Add(pin); //customPins.Add(new CustomPin() { Position = MyPosition, Type = PinType.Place, Label = "Xamarin San Francisco Office", Address = "394 Pacific Ave, San Francisco CA", Id = "Xamarin", Url = "http://xamarin.com/about/" }); var CustomMap = new CustomMap(); CustomMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(MyPosition.Latitude, MyPosition.Longitude), Distance.FromMiles(1))); }
private async Task PinLocationsAsync() // async taak tot ophalen van de locatie { await Task.Run(async() => { Geocoder gc = new Geocoder(); //I believe the suggested format is: //House Number, Street Direction, Street Name, Street Suffix, City, State, Zip, Country //Manueel positie invoeren op UWP MyPosition = new Position(51.134634, 2.763420); PinLabel = $"{KlantAdres}"; PinCollection.Add(new Pin() { Position = MyPosition, Type = PinType.Generic, Label = PinLabel }); var result = await gc.GetPositionsForAddressAsync(KlantAdres); foreach (Position pos in result) { Debug.WriteLine("Lat: {0}, Lng: {1}", pos.Latitude, pos.Longitude); //MyPosition = new Position(pos.Latitude, pos.Longitude); MyPosition = new Position(51.134634, 2.763420); PinLabel = $"{KlantAdres}"; PinCollection.Add(new Pin() { Position = MyPosition, Type = PinType.Generic, Label = PinLabel }); } }); }
public MainViewModel( ) { Task.Run(async() => { var locator = CrossGeolocator.Current; var position = await locator.GetPositionAsync(); MyPosition = new Position(position.Latitude, position.Longitude); }); PinCollection.Add(new Pin() { Position = position2, Type = PinType.Generic, Label = "Taco Truck" }); PinCollection.Add(new Pin() { Position = position3, Type = PinType.Generic, Label = "Noodle Wagon" }); PinCollection.Add(new Pin() { Position = position4, Type = PinType.Generic, Label = "Ice Cream 4Ever" }); }