/// <summary> /// Raises the shared preferences changed event. /// </summary> /// <param name="prefs">Prefs.</param> /// <param name="key">Key.</param> public async void OnSharedPreferenceChanged(ISharedPreferences prefs, string key) { if (ion.context.GetString(Resource.String.pkey_location_gps).Equals(key)) { if (prefs.GetBoolean(key, false)) { ion.appPrefs._location.askForPermissions = true; await InitAsync(); } else { StopAutomaticLocationPolling(); lastKnownLocation = new SimpleLocation() { altitude = ion.preferences.location.customElevation, }; } } else if (ion.context.GetString(Resource.String.pkey_location_elevation).Equals(key)) { lastKnownLocation = new SimpleLocation() { altitude = ion.preferences.location.customElevation, }; } }
protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); GeographyLocation.Register(modelBuilder); SimpleLocation.Register(modelBuilder); }
/// <summary> /// Called when the GoogleApiClient notifies of a location change. /// </summary> /// <param name="location">Location.</param> public void OnLocationChanged(Location location) { var altitude = location.Altitude; if (altitude == 0) { // TODO [email protected]: the altitude provider should not be null if (altitudeProvider != null) { var l = altitudeProvider.lastKnownLocation; if (l != null) { altitude = l.Altitude; } } else { Log.E(this, "The altitude provider was null"); } } if (location.HasAltitude) { lastKnownLocation = new SimpleLocation(true, altitude, location.Longitude, location.Latitude); } else { var altploc = altitudeProvider.lastKnownLocation; if (altploc == null) { altploc = new Location(""); } var alt = Units.Length.FOOT.OfScalar(altploc.Altitude).ConvertTo(ion.preferences.units.length); lastKnownLocation = new SimpleLocation(true, alt.amount, location.Longitude, location.Latitude); } }
private async Task RefreshUiAsync() { if (Settings.MapSizeExpanded) { _leftWidth = _isFlipped ? NarrowForecastWidth : ExpandedMapWidth; _rightWidth = _isFlipped ? ExpandedMapWidth : NarrowForecastWidth; } else { _leftWidth = _isFlipped ? NormalForecastWidth : NormalMapWidth; _rightWidth = _isFlipped ? NormalMapWidth : NormalForecastWidth; } LeftColumnWidth = new GridLength(_leftWidth, GridUnitType.Star); RightColumnWidth = new GridLength(_rightWidth, GridUnitType.Star); _currentLocation = await GetLocationAsync(); if (await SetUpForecastAsync(_currentLocation)) { if (_updateWeatherTimer == null) { // Refresh weather automatically every 6 hours, to lower number of pings _updateWeatherTimer = ThreadPoolTimer.CreatePeriodicTimer(async(t) => { LogService.Write("Silently refreshing weather..."); _currentLocation = await GetLocationAsync(); InvokeOnUIThread(async() => await SetUpForecastAsync(_currentLocation, false)); }, TimeSpan.FromHours(6)); } } }
public string UpdateLocation([FromBody] SimpleLocation simpleLocation) { var location = new Location(simpleLocation); //_mobileMessagingClient.SendNotification(location); return(System.Text.Json.JsonSerializer.Serialize(location)); }
private async Task <bool> SetUpForecastAsync(SimpleLocation location, bool showLoading = true) { if (showLoading) { ShowLoadingPanel(Common.GetLocalizedText("LoadingWeatherInfoText")); } try { CurrentLocation = location.Name; // Set the map center MapCenter = new Geopoint(location.Position); // Add pin MapLayers.Clear(); AddPinToMap(new SimpleLocation(Common.GetLocalizedText("WeatherMapPinLabel"), location.Position.Latitude, location.Position.Longitude)); // Retrieve weather information about location var weather = await WeatherProvider.Instance.GetGenericWeatherAsync(location.Position.Latitude, location.Position.Longitude); // Update the UI if weather is available if (weather != null) { // Only set weather if it's not null _weather = weather; // Update weather-related UI RefreshWeatherUI(_weather); // Try to get sensor data try { SensorTemperatureAndHumidity = await GetSensorTemperatureAndHumidityString(); } catch (Exception ex) { LogService.WriteException(ex); } // Show proper weather panel WeatherErrorPageVisibility = false; WeatherControlVisibility = true; return(true); } else { // Something went wrong so show the error panel WeatherErrorPageVisibility = true; WeatherControlVisibility = false; } } finally { HideLoadingPanel(); } return(false); }
public async Task <bool> SetLocationAsync(SimpleLocation loc) { Location = loc; var result = await RequestFactory.SetLocationRequestFactory().PerformActionAsync(payload: new SetLocationJson() { Location = loc.ToJsonModel() }); return(result); }
public AndroidLocationManager(BaseAndroidION ion) { this.ion = ion; lastKnownLocation = new SimpleLocation() { altitude = ion.preferences.location.customElevation, }; handler = new Handler(Looper.MainLooper); lastTimeLocationChanged = new DateTime(1, 1, 1); }
private async void RefreshButton_Click(object sender, RoutedEventArgs e) { try { _currentLocation = await GetLocationAsync(); await SetUpForecastAsync(_currentLocation, true); } catch (Exception ex) { LogService.Write(ex.ToString(), Windows.Foundation.Diagnostics.LoggingLevel.Error); } }
public bool AttemptSetLocation(Scalar altitude) { if (altitude.unit.quantity != Quantity.Length) { return(false); } else { lastKnownLocation = new SimpleLocation(true, altitude.ConvertTo(Units.Length.METER).amount, double.NaN, double.NaN); return(true); } }
/// <summary> /// Raises the resume event. /// </summary> protected override void OnResume() { base.OnResume(); ion.locationManager.onLocationChanged += OnLocationChanged; var loc = ion.locationManager.lastKnownLocation; if (loc == null) { loc = new SimpleLocation(); } elevation.Text = SensorUtils.ToFormattedString(loc.altitude.ConvertTo(ion.preferences.units.length), true); }
private void AddPinToMap(SimpleLocation location) { MapLayers.Add(new MapElementsLayer { ZIndex = 1, MapElements = new List <MapElement> { new MapIcon { Location = new Geopoint(location.Position), Title = location.Name } } }); }
private void OnAltitudeEvent(GpsAltitudeProvider provider, AltitudeEvent e) { try { if (lastKnownLocation != null) { var loc = lastKnownLocation; lastKnownLocation = new SimpleLocation(true, e.location.Altitude, loc.longitude, loc.latitude); } else { lastKnownLocation = new SimpleLocation(true, e.location.Altitude, e.location.Longitude, e.location.Latitude); } } catch (Exception ex) { Log.E(this, "Failed to resolve altitude event", ex); } }
public List <SimpleLocation> SimpleLocationSpatialSearchByBounds(double southWestLatitude, double southWestLongitude, double northEastLatitude, double northEastLongitude, List <int> optionalLocationGroupFilter) { List <SimpleLocation> result = new List <SimpleLocation>(); using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.CompassDbConnString)) using (SqlConnection conn2 = new SqlConnection(Properties.Settings.Default.CompassDbConnString)) { conn.Open(); conn2.Open(); using (SqlCommand cmd = new SqlCommand()) using (SqlCommand cmd2 = new SqlCommand()) { cmd.Connection = conn; cmd.CommandText = "DECLARE @minY varchar(25) = CAST(@SouthWestLatitude AS varchar(25));" + "\r\n" + "DECLARE @maxY varchar(25) = CAST(@NorthEastLatitude AS varchar(25));" + "\r\n" + "DECLARE @minX varchar(25) = CAST(@SouthWestLongitude AS varchar(25));" + "\r\n" + "DECLARE @maxX varchar(25) = CAST(@NorthEastLongitude AS varchar(25));" + "\r\n" + "" + "\r\n" + "DECLARE @BoundingRect varchar(1024);" + "\r\n" + "" + "\r\n" + "SET @BoundingRect = 'POLYGON((' + @minX + ' ' + @minY + ', ' + " + "\r\n" + " @maxX + ' ' + @minY + ', ' + " + "\r\n" + " @maxX + ' ' + @maxY + ', ' + " + "\r\n" + " @minX + ' ' + @maxY + ', ' + " + "\r\n" + " @minX + ' ' + @minY + '))';" + "\r\n" + "DECLARE @Bounds geography;" + "\r\n" + "SET @Bounds = geography::STPolyFromText(@BoundingRect, 4326);" + "\r\n" + "" + "\r\n" + "SELECT LocationID," + "\r\n" + " LocationTypeEnumCode," + "\r\n" + " LocationGroupEnumCode," + "\r\n" + " [Name]," + "\r\n" + " City," + "\r\n" + " Latitude," + "\r\n" + " Longitude," + "\r\n" + " IncidentDate," + "\r\n" + " Custom" + "\r\n" + " FROM dbo.Location" + "\r\n" + " WHERE Coordinate.STWithin(@Bounds) = 1"; cmd.Parameters.Add("@SouthWestLatitude", System.Data.SqlDbType.Float).Value = southWestLatitude; cmd.Parameters.Add("@SouthWestLongitude", System.Data.SqlDbType.Float).Value = southWestLongitude; cmd.Parameters.Add("@NorthEastLatitude", System.Data.SqlDbType.Float).Value = northEastLatitude; cmd.Parameters.Add("@NorthEastLongitude", System.Data.SqlDbType.Float).Value = northEastLongitude; if (optionalLocationGroupFilter != null && optionalLocationGroupFilter.Count > 0) { int lastIndex = optionalLocationGroupFilter.Count - 1; StringBuilder sb = new StringBuilder(); sb.AppendLine(); for (int i = 0; i < optionalLocationGroupFilter.Count; i++) { int item = optionalLocationGroupFilter[i]; if (i == 0) { sb.Append(" AND ( "); } else { sb.Append(" OR "); } sb.Append("LocationGroupEnumCode = @LocationGroupEnumCode" + i.ToString()); cmd.Parameters.Add("@LocationGroupEnumCode" + i.ToString(), System.Data.SqlDbType.Int).Value = item; if (i == lastIndex) { sb.Append(")"); } else { sb.AppendLine(); } } cmd.CommandText += sb.ToString(); } using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { SimpleLocation newLoc = new SimpleLocation(reader); result.Add(newLoc); } } } } return(result); }
public RedirectToActionResult Index(SimpleLocation loc) { return(RedirectToAction("Index", "WorldTown", loc)); }
public IActionResult WorldTown(SimpleLocation loc) { return(View(loc)); }
public JodelUser(SimpleLocation loc, string deviceUiD) { Location = loc; DeviceUid = deviceUiD; RequestFactory = new JodelRequestFactory(this); }
public List <SimpleLocation> SimpleLocationSpatialSearchByRadius(double latitude, double longitude, double distanceInMeters, List <int> optionalLocationGroupFilter) { List <SimpleLocation> result = new List <SimpleLocation>(); using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.CompassDbConnString)) using (SqlConnection conn2 = new SqlConnection(Properties.Settings.Default.CompassDbConnString)) { conn.Open(); conn2.Open(); using (SqlCommand cmd = new SqlCommand()) using (SqlCommand cmd2 = new SqlCommand()) { cmd.Connection = conn; cmd.CommandText = "DECLARE @Coordinate geography;" + "\r\n" + "" + "\r\n" + "SET @Coordinate = geography::Point (@Latitude, @Longitude, (4326));" + "\r\n" + "" + "\r\n" + "SELECT LocationID," + "\r\n" + " LocationTypeEnumCode," + "\r\n" + " LocationGroupEnumCode," + "\r\n" + " [Name]," + "\r\n" + " City," + "\r\n" + " Latitude," + "\r\n" + " Longitude," + "\r\n" + " IncidentDate," + "\r\n" + " Custom" + "\r\n" + " FROM dbo.Location" + "\r\n" + " WHERE Coordinate.STDistance (@Coordinate) <= @DistanceInMeters"; if (optionalLocationGroupFilter != null && optionalLocationGroupFilter.Count > 0) { int lastIndex = optionalLocationGroupFilter.Count - 1; StringBuilder sb = new StringBuilder(); sb.AppendLine(); for (int i = 0; i < optionalLocationGroupFilter.Count; i++) { int item = optionalLocationGroupFilter[i]; if (i == 0) { sb.Append(" AND ( "); } else { sb.Append(" OR "); } sb.Append("LocationGroupEnumCode = @LocationGroupEnumCode" + i.ToString()); cmd.Parameters.Add("@LocationGroupEnumCode" + i.ToString(), System.Data.SqlDbType.Int).Value = item; if (i == lastIndex) { sb.Append(")"); } else { sb.AppendLine(); } } cmd.CommandText += sb.ToString(); } cmd.Parameters.Add("@Latitude", System.Data.SqlDbType.Float).Value = latitude; cmd.Parameters.Add("@Longitude", System.Data.SqlDbType.Float).Value = longitude; cmd.Parameters.Add("@DistanceInMeters", System.Data.SqlDbType.Float).Value = distanceInMeters; using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { SimpleLocation newLoc = new SimpleLocation(reader); result.Add(newLoc); } } } } return(result); }
public IActionResult Index(SimpleLocation loc) { loc.update(context); return(View(loc)); }
/// <summary> /// Gets location from Settings and if not specified, try to get current position /// </summary> private async Task <SimpleLocation> GetLocationAsync() { var location = new SimpleLocation(Common.GetLocalizedText("WeatherMapPinUnknownLabel"), 0, 0); try { // Immediately return unknown location if location not enabled if (!Settings.IsLocationEnabled) { return(location); } // If the user has specified a location, then AppSettingsVM should have validated // the latitude and longitude, so use that if ((Settings.WeatherLocationLatitude != 0 || Settings.WeatherLocationLongitude != 0) && !string.IsNullOrWhiteSpace(Settings.WeatherLocationString)) { LogService.Write($"Location has been specified in settings - " + $"Name: {Settings.WeatherLocationString}, " + $"Latitude: {Settings.WeatherLocationLatitude}, " + $"Longitude: {Settings.WeatherLocationLongitude}"); location.Position.Latitude = Settings.WeatherLocationLatitude; location.Position.Longitude = Settings.WeatherLocationLongitude; location.Name = Settings.WeatherLocationString; } // Use current location if geolocation is allowed and a specific location wasn't specified else { LogService.Write("No location specified, trying to find current location..."); var accessStatus = await Geolocator.RequestAccessAsync(); if (accessStatus == GeolocationAccessStatus.Allowed) { Geolocator geolocator = new Geolocator(); Geoposition pos = await geolocator.GetGeopositionAsync(); location.Position.Latitude = pos.Coordinate.Point.Position.Latitude; location.Position.Longitude = pos.Coordinate.Point.Position.Longitude; LogService.Write($"Geolocation Position - Latitude: {location.Position.Latitude}, Longitude: {location.Position.Longitude}"); // Try to find the location name using Bing Maps API - this won't work if the Map Service token isn't specified LogService.Write("Attempting to find location name..."); var results = await MapLocationFinder.FindLocationsAtAsync(new Geopoint(location.Position)); if (results.Status == MapLocationFinderStatus.Success && (results.Locations.Count != 0)) { location.Name = results.Locations[0].DisplayName; LogService.Write($"Location found: {location.Name}"); } else { LogService.Write($"Could not find location name ({Enum.GetName(typeof(MapLocationFinderStatus), results.Status)})"); // In the absence of an actual name, use the lat/long location.Name = FormatCurrentLocationString(location.Position.Latitude, location.Position.Longitude); } } else { LogService.Write($"Geolocation Access Status: {Enum.GetName(typeof(GeolocationAccessStatus), accessStatus)}"); } } } catch (Exception ex) { LogService.WriteException(ex); } return(location); }
public JodelUser(SimpleLocation loc) : this(loc, AndroidVerification.GetRandomDeviceUid()) { }
public JodelUser(SimpleLocation loc, string deviceUiD, string accessToken, string refreshToken, string distinctId) : this(loc, deviceUiD) { RefreshToken = refreshToken; AccessToken = accessToken; DistinctId = distinctId; }
// Overridden from ILocationManager public void StopAutomaticLocationPolling() { native.LocationsUpdated -= ResolveLocationChange; isPolling = false; lastKnownLocation = new SimpleLocation(false, 0, 0, 0); }