private void MoveMap(Plugin.Geolocator.Abstractions.Position position) { var center = new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude); var span = new Xamarin.Forms.Maps.MapSpan(center, 1, 1); locationsMap.MoveToRegion(span); }
private async void RefreshSites() { if (IsBusy || !IsActive) { return; } IsBusy = true; if (firstLocation == null) { firstLocation = await _siteService.GetLocation(); if (firstLocation != null) { VisibleRegion = MapSpan.FromCenterAndRadius(new Position(firstLocation.Latitude, firstLocation.Longitude), VisibleRegion.Radius); IsBusy = false; return; } } try { var distanceRadians = DegreesToRadians(Math.Max(VisibleRegion.LatitudeDegrees, VisibleRegion.LongitudeDegrees) / 2); var sites = await _siteService.GetNearBySites(MapCenter.Latitude, MapCenter.Longitude, distanceRadians); Sites = new ObservableCollection <Site>(sites); var pins = new List <ILocationViewModel>(); foreach (var site in sites) { var localSite = site; pins.Add(new LocationViewModel { Key = site.SiteId.ToString(), Title = site.SiteName, Latitude = site.Latitude, Longitude = site.Longitude, Description = string.Format("{0}", site.IsPublic.HasValue ? site.IsPublic.Value ? "Allmän" : "Privat" : string.Empty), Command = new Command(() => DoneCommand.Execute(localSite)) }); } //UpdatePins(pins); Pins = new ObservableCollection <ILocationViewModel>(pins); } finally { IsBusy = false; } }
private void MoveMap(Plugin.Geolocator.Abstractions.Position position) { var center = new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude); var span = new Xamarin.Forms.Maps.MapSpan(center, 1, 1); locationsMap.MoveToRegion(span); using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation)) { //var posts = conn.Table<Post>().ToList(); var places = new List <Place>(); DisplayInMap(places); } }
public async Task <string> GetAdresseFromPosition(Position position) { bool isInternetAvailable = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable(); if (!isInternetAvailable && !CrossGeolocator.IsSupported || !CrossGeolocator.Current.IsGeolocationEnabled || !CrossGeolocator.Current.IsGeolocationAvailable) { return("Adresse inconnue"); } else { var geolocatorPosition = new Plugin.Geolocator.Abstractions.Position(position.Latitude, position.Longitude); Address adresse = (await CrossGeolocator.Current.GetAddressesForPositionAsync(geolocatorPosition)).ToList().First(); return(adresse.SubThoroughfare + " " + adresse.Thoroughfare + ", " + adresse.PostalCode + " " + adresse.Locality); } }
public async void InitGeolocator() { try { IGeolocator locator = CrossGeolocator.Current; locator.DesiredAccuracy = 50; Plugin.Geolocator.Abstractions.Position position = await locator.GetPositionAsync(20000); currentPosition = new Position(position.Latitude, position.Longitude); Location.CurrentPosition = currentPosition; map.MoveToRegion(MapSpan.FromCenterAndRadius(currentPosition, Distance.FromKilometers(5))); Location.InitDistance(position.Latitude, position.Longitude); _currentLocation = true; } catch (GeolocationException e) { await DisplayAlert("No Location!", "Geolocation Failed.", "OK"); } catch (Exception e) { await DisplayAlert("Oh no..!", "God help you!", "OK"); } }
public void MoveToRegion(Plugin.Geolocator.Abstractions.Position position) { ClosestBankMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(position.Latitude, position.Longitude), Distance.FromKilometers(0.5))); }
private async void RefreshSites() { if (IsBusy || !IsActive) { return; } IsBusy = true; if (firstLocation == null) { firstLocation = await _siteService.GetLocation(); if (firstLocation != null) { VisibleRegion = MapSpan.FromCenterAndRadius(new Position(firstLocation.Latitude, firstLocation.Longitude), VisibleRegion.Radius); IsBusy = false; return; } } try { var distanceRadians = DegreesToRadians(Math.Max(VisibleRegion.LatitudeDegrees, VisibleRegion.LongitudeDegrees)/2); var sites = await _siteService.GetNearBySites(MapCenter.Latitude, MapCenter.Longitude, distanceRadians); Sites = new ObservableCollection<Site>(sites); var pins = new List<ILocationViewModel>(); foreach (var site in sites) { var localSite = site; pins.Add(new LocationViewModel { Key = site.SiteId.ToString(), Title = site.SiteName, Latitude = site.Latitude, Longitude = site.Longitude, Description = string.Format("{0}", site.IsPublic.HasValue ? site.IsPublic.Value ? "Allmän" : "Privat" : string.Empty), Command = new Command(() => DoneCommand.Execute(localSite)) }); } //UpdatePins(pins); Pins = new ObservableCollection<ILocationViewModel>(pins); } finally { IsBusy = false; } }
public async void Load() { try { var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location); if (status != PermissionStatus.Granted) { if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location)) { await DisplayAlert("Need location", "Gunna need that location", "OK"); } var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location); status = results[Permission.Location]; } if (status == PermissionStatus.Granted) { _map = new Map() { IsShowingUser = false, VerticalOptions = LayoutOptions.FillAndExpand, MapType = MapType.Street }; MapContainer.Children.Add(_map); MainPageViewModel viewModel = this.BindingContext as MainPageViewModel; if (viewModel != null) { viewModel.PropertyChanged += delegate(object sender, PropertyChangedEventArgs args) { if (args.PropertyName.Equals("GpsPosition", StringComparison.CurrentCultureIgnoreCase)) { } }; IGeolocator geoLocator = CrossGeolocator.Current; geoLocator.AllowsBackgroundUpdates = true; geoLocator.DesiredAccuracy = 50; if (!geoLocator.IsListening) { var listening = await geoLocator.StartListeningAsync(1000, 5); if ((listening && geoLocator.IsListening) && (geoLocator.IsGeolocationAvailable && geoLocator.IsGeolocationEnabled)) { geoLocator.PositionChanged += delegate(object sender, PositionEventArgs args) { var position = new Position(args.Position.Latitude, args.Position.Longitude); SetMapsPosition(position); }; } } else { Plugin.Geolocator.Abstractions.Position p = await geoLocator.GetPositionAsync(1000); var position = new Position(p.Latitude, p.Longitude); SetMapsPosition(position); } } } else if (status != PermissionStatus.Unknown) { await DisplayAlert("Location Denied", "Can not continue, try again.", "OK"); } } catch (Exception ex) { } }
private void MoveMap(Plugin.Geolocator.Abstractions.Position position) { LocationsMap.MoveToRegion(new MapSpan(new Position(position.Latitude, position.Longitude), 1, 1)); }
//(CDLTLL) RefreshMap() with real data loading from services/mock is called only if VisibleRegion or Map-Zoom has changed private async void ReloadMapInfo() { if (IsBusy) { return; } IsBusy = true; if (_firstLocation == null) { _firstLocation = await GetLocation(); if (_firstLocation != null) { VisibleRegion = MapSpan.FromCenterAndRadius(new Position(_firstLocation.Latitude, _firstLocation.Longitude), VisibleRegion.Radius); IsBusy = false; return; } } try { var distanceRadians = DegreesToRadians(Math.Max(VisibleRegion.LatitudeDegrees, VisibleRegion.LongitudeDegrees) / 2); var center = VisibleRegion.Center; var halfheightDegrees = VisibleRegion.LatitudeDegrees / 2; var halfwidthDegrees = VisibleRegion.LongitudeDegrees / 2; var topLatitude = center.Latitude + halfheightDegrees; var leftLongitude = center.Longitude - halfwidthDegrees; var bottomLatitude = center.Latitude - halfheightDegrees; var rightLongitude = center.Longitude + halfwidthDegrees; // Adjust for Internation Date Line (+/- 180 degrees longitude) if (leftLongitude < -180) { leftLongitude = 180 + (180 + leftLongitude); } if (rightLongitude > 180) { rightLongitude = (rightLongitude - 180) - 180; } // (CDLTLL) Query and obtain data from a real service or from the mock service depending on the injected implementation var vehiclesInCurrentMapArea = await _vehiclesService.GetVehiclesInArea(this.UrlPrefix, CurrentTenantId, topLatitude, leftLongitude, bottomLatitude, rightLongitude); //(CDLTLL - Check this, not being used) Vehicles = new ObservableCollection <Vehicle>(vehiclesInCurrentMapArea); var pinsList = new List <ILocationViewModel>(); foreach (Vehicle vehicle in vehiclesInCurrentMapArea) { Vehicle localVehicle = vehicle; pinsList.Add(new LocationViewModel { Key = vehicle.Id.ToString(), Title = vehicle.Make + " " + vehicle.Model, Latitude = vehicle.Latitude, Longitude = vehicle.Longitude, Description = "LicensePlate: " + vehicle.LicensePlate, Command = new Command(() => DoneCommand.Execute(localVehicle)) }); } //UpdatePins(pins); if (Pins != null) { Pins.Clear(); } Pins = new ObservableCollection <ILocationViewModel>(pinsList); } finally { IsBusy = false; } }
private async Task <Plugin.Geolocator.Abstractions.Position> FetchLocation() { _lastPosition = await _geolocator.GetPositionAsync(timeoutMilliseconds : 10000); return(_lastPosition); }