private async Task <bool> UpdateMyLocation() { try { var newLocation = await _locationProvider.GetLocationAsync(); if (newLocation == null) { return(false); } var distance = Utilities.GpsUtils.Distance(myLocation, newLocation); if (distance < 100 && Math.Abs(myLocation.Altitude - newLocation.Altitude) < 30) { return(false); } bool needRefresh = false; if (distance > 100) { myLocation.Latitude = newLocation.Latitude; myLocation.Longitude = newLocation.Longitude; needRefresh = true; } //keep old location if new location has no altitude if (!Utilities.GpsUtils.HasAltitude(myLocation) || (Utilities.GpsUtils.HasAltitude(newLocation) && Math.Abs(newLocation.Altitude - myLocation.Altitude) > 100)) { myLocation.Altitude = newLocation.Altitude; needRefresh = true; } if (needRefresh) { var poi = Database.GetNearestPoi(myLocation, iGpsUtilities); if (poi != null) { myLocationPlaceInfo = new PlaceInfo(poi.Poi.Name, poi.Poi.Country); } else { myLocationPlaceInfo = (await PlaceNameProvider.AsyncGetPlaceName(myLocation)); } } return(needRefresh); } catch (Exception ex) { LogError("Location update error", ex); return(false); } }
public static async Task <PoiCountry?> GetDefaultCountryByPhoneLocation() { PoiCountry?defaultCountry = null; var location = await GpsLocationProvider.GetLastKnownLocationAsync(); if (location != null) { var placeInfo = await PlaceNameProvider.AsyncGetPlaceName(location); defaultCountry = placeInfo?.Country; } if (!defaultCountry.HasValue) { defaultCountry = PoiCountryHelper.GetDefaultCountryByPhoneSettings(); } return(defaultCountry); }
private void UpdateLocationName(GpsLocation location) { Task.Run(async() => { var placeInfo = await PlaceNameProvider.AsyncGetPlaceName(location); MainThread.BeginInvokeOnMainThread(() => { _editTextName.Text = placeInfo.PlaceName; var countryIndex = (_spinnerCountry.Adapter as CountryAdapter).GetPosition(placeInfo.Country); if (countryIndex >= 0) { _spinnerCountry.SetSelection(countryIndex); } } ); } ); }
public static async Task <PhotoData> Import(string path, ExifData exifData, IAppContext appContext) { using (FileStream fs = System.IO.File.OpenRead(path)) { byte[] bytes; using (BinaryReader br = new BinaryReader(fs)) { bytes = br.ReadBytes((int)fs.Length); } var bmp = BitmapFactory.DecodeByteArray(bytes, 0, bytes.Length); var imgWidth = bmp.Width; var imgHeight = bmp.Height; var thumbWidth = THUMBNAIL_WIDTH; var thumbHeight = THUMBNAIL_HEIGHT; var filename = ImageSaverUtils.GetPhotoFileName(); var filepath = System.IO.Path.Combine(ImageSaverUtils.GetPhotosFileFolder(), filename); var file = new Java.IO.File(filepath); byte[] thumbnail = ImageResizer.ResizeImageAndroid(bytes, thumbWidth, thumbHeight, THUMBNAIL_QUALITY); using (var output = new Java.IO.FileOutputStream(file)) { output.Write(bytes); } PoiDatabase poiDatabase = new PoiDatabase(); string jsonCategories = JsonConvert.SerializeObject(appContext.Settings.Categories); PhotoData photodata = new PhotoData { Datetime = DateTime.Now, DatetimeTaken = exifData.timeTaken ?? DateTime.Now, PhotoFileName = filename, Longitude = exifData.location?.Longitude ?? 0, Latitude = exifData.location?.Latitude ?? 0, Altitude = exifData.location?.Altitude ?? 0, Heading = exifData.heading, LeftTiltCorrector = 0, RightTiltCorrector = 0, Thumbnail = thumbnail, JsonCategories = jsonCategories, PictureWidth = imgWidth, PictureHeight = imgHeight, MinAltitude = appContext.Settings.MinAltitute, MaxDistance = appContext.Settings.MaxDistance, FavouriteFilter = appContext.ShowFavoritesOnly, ShowElevationProfile = appContext.Settings.ShowElevationProfile }; //calculate view angle from focal length equivalent on 35mm camera, or use default viev angle 60dg var viewAngle = exifData.focalLength35mm.HasValue ? 2 * System.Math.Tan(35d / 2d / (double)exifData.focalLength35mm.Value) / System.Math.PI * 180 : 60; if (imgWidth > imgHeight) { photodata.ViewAngleHorizontal = viewAngle; photodata.ViewAngleVertical = viewAngle / imgWidth * imgHeight; } else { photodata.ViewAngleHorizontal = viewAngle / imgHeight * imgWidth; photodata.ViewAngleVertical = viewAngle; } if (GpsUtils.HasLocation(exifData.location)) { var placeInfo = await PlaceNameProvider.AsyncGetPlaceName(exifData.location); photodata.Tag = placeInfo.PlaceName + " -> ?"; } else { photodata.Tag = "? -> ?"; } appContext.PhotosModel.InsertItem(photodata); return(photodata); } }