private MKCoordinateRegion BuildVisibleRegion(LocationCoordinate currentLocation)
        {
            var span   = new MKCoordinateSpan(0.003125, 0.003125);
            var region = new MKCoordinateRegion(new CLLocationCoordinate2D(currentLocation.Latitude, currentLocation.Longitude), span);

            return(region);
        }
Esempio n. 2
0
        public static LocationCoordinate GetUserInputLocationCoordinate(DataGridView dataGridViewMap, int?columnIndex, FileEntryAttribute fileEntryAttribute)
        {
            if (!DataGridViewHandler.GetIsAgregated(dataGridViewMap))
            {
                return(null);
            }
            if (columnIndex == null)
            {
                columnIndex = DataGridViewHandler.GetColumnIndexUserInput(dataGridViewMap, fileEntryAttribute);
            }
            if (columnIndex == -1)
            {
                return(null);
            }
            if (!DataGridViewHandler.IsColumnPopulated(dataGridViewMap, (int)columnIndex))
            {
                return(null);
            }

            LocationCoordinate locationCoordinate;
            string             locationCoordinateString = DataGridViewHandler.GetCellValueNullOrStringTrim(dataGridViewMap, (int)columnIndex, headerMedia, tagMediaCoordinates);

            if (!string.IsNullOrEmpty(locationCoordinateString))
            {
                locationCoordinateString = locationCoordinateString.TrimEnd('+');
            }
            locationCoordinate = LocationCoordinate.Parse(locationCoordinateString);
            return(locationCoordinate);
        }
        public void Pay(PLVDevice device, string paymentAmount)
        {
            if (device == null)
            {
                // Payleven: device not found
                StatusAction.Invoke(PLVPaylevenStatus.PLVPaylevenStatusDeviceNotFound);
                return;
            }

            if (!LocationCoordinate.IsValid())
            {
                // Payleven: coordinates are not valid
                StatusAction.Invoke(PLVPaylevenStatus.PLVPaylevenStatusCoordsIsNotValid);
                return;
            }

            var paymentRequest = new PLVPaymentRequest(PaymentHelper.GetRandomNSString(), PaymentHelper.LocaleAmount(paymentAmount),
                                                       Currency, LocationCoordinate);

            var paymentTask = Payleven.PaymentTaskWithRequest(paymentRequest, device, this);

            if (paymentTask == null)
            {
                // Payleven: error with creating payment
                StatusAction.Invoke(PLVPaylevenStatus.PLVPaylevenStatusError);
                return;
            }
            else
            {
                // Payleven: payment has started!
                paymentTask.Start();
            }
        }
Esempio n. 4
0
        public static bool GetUserInputIsCreateNewAccurateLocationUsingSearchLocation(DataGridView dataGridViewMap, int?columnIndex, FileEntryAttribute fileEntryAttribute)
        {
            if (!DataGridViewHandler.GetIsAgregated(dataGridViewMap))
            {
                return(false);
            }
            if (columnIndex == null)
            {
                columnIndex = DataGridViewHandler.GetColumnIndexUserInput(dataGridViewMap, fileEntryAttribute);
            }
            if (columnIndex == -1)
            {
                return(false);
            }
            if (!DataGridViewHandler.IsColumnPopulated(dataGridViewMap, (int)columnIndex))
            {
                return(false);
            }
            string locationCoordinateString = DataGridViewHandler.GetCellValueNullOrStringTrim(dataGridViewMap, (int)columnIndex, headerMedia, tagMediaCoordinates);

            if (string.IsNullOrEmpty(locationCoordinateString))
            {
                return(false);
            }
            LocationCoordinate locationCoordinate = LocationCoordinate.Parse(locationCoordinateString.TrimEnd('+'));

            if (locationCoordinate == null)
            {
                return(false);
            }

            return(locationCoordinateString.EndsWith("+"));
        }
Esempio n. 5
0
        public static void UpdateBrowserMap(ChromiumWebBrowser chromiumWebBrowser, LocationCoordinate locationCoordinate, int zoomLevel, MapProvider mapProvider)
        {
            switch (mapProvider)
            {
            case MapProvider.OpenStreetMap:
                //https://www.google.com/maps/search/59.902056,+10.743139/@59.902056,10.7409503,17z
                //https://www.google.com/maps/search/59.902056,10.743139
                //https://www.latlong.net/c/?lat=59.902827&long=10.754396
                //https://www.openstreetmap.org/?mlat=51.510772705078125&mlon=0.054931640625#map=13/51.5147/0.0494

                chromiumWebBrowser.Load("https://www.openstreetmap.org/?mlat=" +
                                        locationCoordinate.Latitude.ToString(CultureInfo.InvariantCulture) +
                                        "&mlon=" + locationCoordinate.Longitude.ToString(CultureInfo.InvariantCulture) +
                                        "#map=" + zoomLevel.ToString() +
                                        "/" + locationCoordinate.Latitude.ToString(CultureInfo.InvariantCulture) +
                                        "/" + locationCoordinate.Longitude.ToString(CultureInfo.InvariantCulture));
                break;

            case MapProvider.GoogleMap:
                //https://www.google.com/maps/@53.8576492,27.7043077,15z

                /*chromiumWebBrowser.Load("https://www.google.com/maps/@" +
                 *  locationCoordinate.Latitude.ToString(CultureInfo.InvariantCulture) +
                 *  "," + locationCoordinate.Longitude.ToString(CultureInfo.InvariantCulture) +
                 *  "," + ConvertZoomLevelToGoogle(zoomLevel).ToString() + "z");*/
                //https://www.google.com/maps/search/?api=1&query=59.97775%2C10.67877
                chromiumWebBrowser.Load("https://www.google.com/maps/search/?api=1&query=" +
                                        locationCoordinate.Latitude.ToString(CultureInfo.InvariantCulture) +
                                        "%2C" + locationCoordinate.Longitude.ToString(CultureInfo.InvariantCulture));
                break;
            }
        }
        public void should_calculate_the_distance_correctly_between_two_points()
        {
            var london = new LocationCoordinate(51.500288, -0.126269);
            var paris  = new LocationCoordinate(48.856495, 2.350907);

            var result = Resolve <IDistanceCalculatorService>().DistanceBetween(london, paris) / 1000;

            Assert.That(result, Is.AtLeast(342));
            Assert.That(result, Is.AtMost(343));
        }
Esempio n. 7
0
 private DataGridViewGenericRow(string headerName, string rowName, ReadWriteAccess readWriteAcess, bool isHeader, bool isMultiLine, PropertyKey propertyKey,
                                Metadata metadata, FileEntryAttribute fileEntryAttribute,
                                MetadataPriorityKey metadataPriorityKey, LocationCoordinate locationCoordinate)
 {
     this.HeaderName          = headerName ?? throw new ArgumentNullException(nameof(rowName));
     this.RowName             = rowName == null ? "" : rowName;
     this.ReadWriteAccess     = readWriteAcess;
     this.IsHeader            = isHeader;
     this.IsEqual             = false;
     this.IsFavourite         = false;
     this.IsMultiLine         = isMultiLine;
     this.PropertyKey         = propertyKey;
     this.Metadata            = metadata;
     this.FileEntryAttribute  = fileEntryAttribute;
     this.MetadataPriorityKey = metadataPriorityKey;
     this.LocationCoordinate  = locationCoordinate;
 }
Esempio n. 8
0
        private void GetLocationAndShow(MapProvider mapProvider)
        {
            List <LocationCoordinate> locationCoordinates = new List <LocationCoordinate>();

            DataGridView dataGridView = dataGridViewMap;

            foreach (DataGridViewCell dataGridViewCell in dataGridView.SelectedCells)
            {
                if (LocationCoordinate.TryParse(DataGridViewHandler.GetCellValueNullOrStringTrim(dataGridView, dataGridViewCell.ColumnIndex, dataGridViewCell.RowIndex), out LocationCoordinate locationCoordinate))
                {
                    if (!locationCoordinates.Contains(locationCoordinate))
                    {
                        locationCoordinates.Add(locationCoordinate);
                    }
                }
            }
            ShowMediaOnMap.UpdatedBroswerMap(browser, locationCoordinates, GetZoomLevel(), mapProvider);
        }
Esempio n. 9
0
        private static void CalulateLocationDistanceAndCenterPoints(List <LocationCoordinate> locationCoordinates,
                                                                    out LocationCoordinate locationCoordinateMap, out LocationCoordinate locationCoordinateMin, out LocationCoordinate locationCoordinateMax)
        {
            bool  isDefaultSet = false;
            float maxLongitude = 0;
            float minLongitude = 0;
            float maxLatitude  = 0;
            float minLatitude  = 0;

            foreach (LocationCoordinate locationCoordinate in locationCoordinates)
            {
                if (!isDefaultSet)
                {
                    isDefaultSet = true;
                    maxLongitude = locationCoordinate.Longitude;
                    minLongitude = locationCoordinate.Longitude;
                    maxLatitude  = locationCoordinate.Latitude;
                    minLatitude  = locationCoordinate.Latitude;
                }
                if (locationCoordinate.Longitude > maxLongitude)
                {
                    maxLongitude = locationCoordinate.Longitude;
                }
                if (locationCoordinate.Longitude < minLongitude)
                {
                    minLongitude = locationCoordinate.Longitude;
                }
                if (locationCoordinate.Latitude > maxLatitude)
                {
                    maxLatitude = locationCoordinate.Latitude;
                }
                if (locationCoordinate.Latitude < minLatitude)
                {
                    minLatitude = locationCoordinate.Latitude;
                }
            }

            float mapLongitude = (maxLongitude + minLongitude) / 2;
            float mapLatitude  = (maxLatitude + minLatitude) / 2;

            locationCoordinateMin = new LocationCoordinate(minLatitude, minLongitude);
            locationCoordinateMax = new LocationCoordinate(maxLatitude, maxLongitude);
            locationCoordinateMap = new LocationCoordinate(mapLatitude, mapLongitude);
        }
        private void BuildMapView(LocationCoordinate currentLocation)
        {
            var visibleRegion = this.BuildVisibleRegion(currentLocation);

            this.mapView = new MKMapView()
            {
                ShowsUserLocation = true,
                ZoomEnabled       = true
            };

            this.mapView.SizeToFit();
            this.mapView.Frame = new RectangleF(0, this.toolbar.Bounds.Height, this.View.Frame.Width, this.View.Frame.Height - this.toolbar.Bounds.Height);
            this.mapView.SetRegion(visibleRegion, true);
            this.mapView.Delegate = this.GeofenceMapDelegate;

            this.View.AddSubview(this.toolbar);
            this.View.AddSubview(this.mapView);
            this.SetupGestureInteraction();
        }
Esempio n. 11
0
        private void UpdateBrowserMap(string combinedCorordinateString, MapProvider mapProvider)
        {
            if (ClipboardUtility.IsClipboardActive && ClipboardUtility.NuberOfItemsToEdit > 1)
            {
                return;
            }
            DataGridView dataGridView = dataGridViewMap;

            if (DataGridViewHandler.GetCellSelectedCount(dataGridView) == 1) //Only updated the Browser Map when one cell are updated
            {
                LocationCoordinate locationCoordinate = LocationCoordinate.Parse(combinedCorordinateString);

                if (locationCoordinate != null)
                {
                    locationCoordinateRememberForZooming = new LocationCoordinate(locationCoordinate.Latitude, locationCoordinate.Longitude);
                    ShowMediaOnMap.UpdateBrowserMap(browser, locationCoordinate, GetZoomLevel(), mapProvider);
                }
            }
        }
Esempio n. 12
0
        private void PopulateDataGridViewMapWithBrowserCoordinate(DataGridView dataGridView, string text)
        {
            if (dataGridView.CurrentCell == null && dataGridView.SelectedCells.Count < 1)
            {
                return;
            }

            LocationCoordinate locationCoordinate = ParseCoordinateFromURL(text);

            if (locationCoordinate != null)
            {
                List <int> selectedColumns = DataGridViewHandler.GetColumnSelected(dataGridView);

                foreach (int columnIndex in selectedColumns)
                {
                    DataGridViewHandler.SetCellValue(dataGridView, columnIndex,
                                                     DataGridViewHandlerMap.headerBrowser, DataGridViewHandlerMap.tagMediaCoordinates, locationCoordinate.ToString());
                }
            }
        }
        public async Task <CommandResult> Handle(RegisterLocationCoordinatesCommand message)
        {
            LocationCoordinate locationCoordinate = null;

            foreach (var registerLocationCoordinate in message.RegisterLocationCoordinatesList)
            {
                //Validate using domain models
                locationCoordinate = _mapper.Map <RegisterLocationCoordinateItem, LocationCoordinate>(registerLocationCoordinate);


                if (!string.IsNullOrEmpty(registerLocationCoordinate.LocationCode))
                {
                    //Get LocationTypeId
                    int locationId = await _locationRepository.GetLocationId(registerLocationCoordinate.LocationCode);

                    locationCoordinate.LocationId = locationId;
                }

                //if is not valid
                if (locationCoordinate.HasErrors)
                {
                    return(locationCoordinate.ToResult());
                }


                //Insert
                _locationCoordinateRepository.Add(locationCoordinate);

                await _unitOfWork.CommitAsync();

                //Publish bussines Event
                await _bus.PublishAsync(new LocationCoordinateRegistered()
                {
                    LocationCoordinateId = locationCoordinate.LocationCoordinateId
                });
            }

            //Return result
            return(locationCoordinate.ToResult());
        }
Esempio n. 14
0
        private LocationCoordinate ParseCoordinateFromURL(string text)
        {
            /*
             * Normal:                                                     #map=15/59.9415/10.6785&layers=N
             * Note:       note/new?   lat=59.9419&lon=10.6814             #map=15/59.9415/10.6861&layers=N
             * Center:     query?      lat=59.9420&lon=10.6847             #map=15/59.9421/10.6805&layers=N
             * Address:    search?whereami=1&  query=59.9417%2C10.6740     #map=15/59.9417/10.6740&layers=N
             * Search:     search?             query=59.9417%2C10.6740     #map=15/59.9417/10.6740&layers=N
             */
            LocationCoordinate locationCoordinate = null;

            if (text.ToLower().StartsWith("https://www.openstreetmap.org/"))
            {
                string url = text;
                string string_lon;
                string string_lat;
                int    index_sperator;
                int    index_lat = url.IndexOf("lat=");
                if (index_lat >= 0)
                {
                    index_sperator = url.IndexOf("&", index_lat);
                    if (index_sperator <= index_lat)
                    {
                        index_sperator = url.IndexOf("%2C", index_lat);
                    }
                    if (index_sperator <= index_lat)
                    {
                        return(locationCoordinate);                             //Not found, can't find values
                    }
                    string_lat = url.Substring(index_lat + 4, index_sperator - index_lat - 4);

                    int index_lon = url.IndexOf("lon=");
                    if (index_lon <= index_lat)
                    {
                        return(locationCoordinate);
                    }
                    index_sperator = url.IndexOf("#map", index_lon);
                    if (index_sperator == -1)
                    {
                        index_sperator = url.Length;                       //Not found, can't find values
                    }
                    string_lon = url.Substring(index_lon + 4, index_sperator - index_lon - 4);
                }
                else
                {
                    const int coordLength = 11;
                    index_lat = url.IndexOf("query=") + 6;
                    if (index_lat >= 0 && index_lat + coordLength <= url.Length)
                    {
                        index_sperator = url.IndexOf("%2C", index_lat, coordLength);
                        if (index_sperator == -1)
                        {
                            index_sperator = url.IndexOf("&", index_lat, 9);
                        }
                        if (index_sperator == -1)
                        {
                            return(locationCoordinate);                      //Not found, can't find seperator
                        }
                        string_lat = url.Substring(index_lat, index_sperator - index_lat);

                        int index_lon = -1;
                        if (url.IndexOf("%2C", index_lat, 11) != -1)
                        {
                            index_lon = index_sperator + 3;
                        }
                        if (url.IndexOf("&", index_lat, 9) != -1)
                        {
                            index_lon = index_sperator + 1;
                        }
                        if (index_lon == -1)
                        {
                            return(locationCoordinate);
                        }

                        index_sperator = url.IndexOf("#map", index_lon);
                        if (index_sperator == -1)
                        {
                            index_sperator = url.Length;
                        }

                        string_lon = url.Substring(index_lon, index_sperator - index_lon);
                    }
                    else
                    {
                        return(locationCoordinate);
                    }
                }

                float lat;
                float lon;
                if (float.TryParse(string_lon, NumberStyles.Float, CultureInfo.InvariantCulture, out lon) &&
                    float.TryParse(string_lat, NumberStyles.Float, CultureInfo.InvariantCulture, out lat))
                {
                    locationCoordinate = new LocationCoordinate(lat, lon);
                }
            }

            if (text.ToLower().StartsWith("https://www.google.com/maps/"))
            {
                string[] split = text.Split('@');
                if (split.Length >= 2)
                {
                    string[] coordinates = split[1].Split(',');
                    if (coordinates.Length >= 2)
                    {
                        float lat;
                        float lon;
                        if (float.TryParse(coordinates[1], NumberStyles.Float, CultureInfo.InvariantCulture, out lon) &&
                            float.TryParse(coordinates[0], NumberStyles.Float, CultureInfo.InvariantCulture, out lat))
                        {
                            locationCoordinate = new LocationCoordinate(lat, lon);
                        }
                    }
                }
            }
            return(locationCoordinate);
        }
Esempio n. 15
0
        public static void PopulateGrivViewMapNomnatatim(DataGridView dataGridView, int columnIndex, LocationCoordinate locationCoordinateSearch,
                                                         bool onlyFromCache, bool canReverseGeocoder, bool forceReloadUsingReverseGeocoder, bool createNewAccurateLocationUsingSearchLocation)
        {
            GlobalData.IsPopulatingMapLocation = true;
            try
            {
                LocationCoordinateAndDescription locationCoordinateAndDescriptionInDatabase = null;

                float locationAccuracyLatitude  = Properties.Settings.Default.LocationAccuracyLatitude;
                float locationAccuracyLongitude = Properties.Settings.Default.LocationAccuracyLongitude;

                //LocationDescription locationDescription = null;
                LocationDescription locationDescription = null;

                #region Get Location Info from User when allowed
                DataGridViewGenericColumn dataGridViewGenericColumn = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridView, columnIndex);
                if (!forceReloadUsingReverseGeocoder && dataGridViewGenericColumn?.Metadata != null)
                {
                    #region Get UserInput Location data
                    Metadata metadataUser = new Metadata(MetadataBrokerType.Empty);
                    GetUserInputChanges(dataGridView, ref metadataUser, null, columnIndex);
                    #endregion

                    if (!string.IsNullOrEmpty(metadataUser.LocationName) || !string.IsNullOrEmpty(metadataUser.LocationCity) ||
                        !string.IsNullOrEmpty(metadataUser.LocationState) || !string.IsNullOrEmpty(metadataUser.LocationCountry))
                    {
                        locationDescription = new LocationDescription(metadataUser.LocationName, metadataUser.LocationCity, metadataUser.LocationState, metadataUser.LocationCountry);

                        #region createNewAccurateLocationUsingSearchLocation
                        if (createNewAccurateLocationUsingSearchLocation)
                        {
                            try
                            {
                                LocationCoordinateAndDescription locationCoordinateAndDescriptionFromUserInput = new LocationCoordinateAndDescription(
                                    locationCoordinateSearch, locationDescription);
                                DatabaseAndCacheLocationAddress.WriteLocationName(locationCoordinateSearch, locationCoordinateAndDescriptionFromUserInput);

                                dataGridView.EndEdit();
                                //Remove + sign
                                AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagMediaCoordinates,
                                                                                             ReadWriteAccess.AllowCellReadAndWrite), locationCoordinateSearch.ToString(), false);
                            }
                            catch
                            {
                                //DEBUG
                            }
                        }
                        #endregion
                    }
                }
                #endregion

                if (locationCoordinateSearch != null)
                {
                    #region Get Nearby Location Coordinate and Info in Database
                    locationCoordinateAndDescriptionInDatabase = DatabaseAndCacheLocationAddress.AddressLookupAndReverseGeocoder(
                        locationCoordinateSearch, locationAccuracyLatitude, locationAccuracyLongitude, onlyFromCache: onlyFromCache,
                        canReverseGeocoder: canReverseGeocoder, metadataLocationDescription: locationDescription, forceReloadUsingReverseGeocoder: false);
                    #endregion



                    #region If Asked to Reload, reload from UsingReverseGeocoder
                    if (forceReloadUsingReverseGeocoder && locationCoordinateAndDescriptionInDatabase != null)
                    {
                        locationCoordinateAndDescriptionInDatabase = DatabaseAndCacheLocationAddress.AddressLookupAndReverseGeocoder(
                            locationCoordinateSearch, locationAccuracyLatitude, locationAccuracyLongitude, onlyFromCache: false,
                            canReverseGeocoder: true, metadataLocationDescription: null, forceReloadUsingReverseGeocoder: true);
                    }
                    #endregion
                }
                else
                {
                    #region No coordinates found
                    AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerMedia, tagMediaCoordinates,
                                                                                 ReadWriteAccess.AllowCellReadAndWrite), null, false);
                    #endregion
                }
                #region Show Tooltip when Use need Nearby coordinate
                int rowIndex = DataGridViewHandler.GetRowIndex(dataGridView, headerMedia, tagMediaCoordinates);
                if (locationCoordinateAndDescriptionInDatabase != null && locationCoordinateSearch != locationCoordinateAndDescriptionInDatabase.Coordinate)
                {
                    DataGridViewHandler.SetCellToolTipText(dataGridView, columnIndex, rowIndex, "Near by location used: " + locationCoordinateAndDescriptionInDatabase.Coordinate.ToString());
                }
                else
                {
                    DataGridViewHandler.SetCellToolTipText(dataGridView, columnIndex, rowIndex, "");
                }
                #endregion

                #region No data location data loaded, set as readonly
                bool isReadOnly = (locationCoordinateAndDescriptionInDatabase == null);
                #endregion

                #region Updated DataGridView with new data
                AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerNominatim, tagLocationName, ReadWriteAccess.AllowCellReadAndWrite),
                       locationCoordinateAndDescriptionInDatabase?.Description.Name, isReadOnly);
                AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerNominatim, tagCity, ReadWriteAccess.AllowCellReadAndWrite),
                       locationCoordinateAndDescriptionInDatabase?.Description.City, isReadOnly);
                AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerNominatim, tagProvince, ReadWriteAccess.AllowCellReadAndWrite),
                       locationCoordinateAndDescriptionInDatabase?.Description.Region, isReadOnly);
                AddRow(dataGridView, columnIndex, new DataGridViewGenericRow(headerNominatim, tagCountry, ReadWriteAccess.AllowCellReadAndWrite),
                       locationCoordinateAndDescriptionInDatabase?.Description.Country, isReadOnly);
                #endregion
            }
            catch (Exception ex)
            {
                KryptonMessageBox.Show("Unexpected error occur.\r\nException message:" + ex.Message + "\r\n",
                                       "Unexpected error occur", MessageBoxButtons.OK, MessageBoxIcon.Error, showCtrlCopy: true);
            }
            finally
            {
                GlobalData.IsPopulatingMapLocation = false;
            }
        }
Esempio n. 16
0
        public static void PopulateTimeZone(DataGridView dataGridViewDateTime, int?columnIndexDateTime, FileEntryAttribute fileEntryAttribute)
        {
            #region Check if all data IsAgregated, //need this check, due to Maps tab also updated this, when coordinates has been updated
            if (!DataGridViewHandler.GetIsAgregated(dataGridViewDateTime))
            {
                return;
            }
            if (columnIndexDateTime == null)
            {
                columnIndexDateTime = DataGridViewHandler.GetColumnIndexUserInput(dataGridViewDateTime, fileEntryAttribute);
            }
            if (columnIndexDateTime == -1)
            {
                return;
            }
            int columnIndex = (int)columnIndexDateTime;
            DataGridViewGenericColumn dataGridViewGenericColumn = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridViewDateTime, columnIndex);
            if (dataGridViewGenericColumn == null)
            {
                return;
            }
            #endregion

            #region Get Media Date&Time and GPS Location Date&time from DataGridView or use Metadata
            //Get Date and Time for DataGridView
            DateTime?metadataMediaDateTaken   = GetUserInputDateTaken(dataGridViewDateTime, columnIndex, null);
            DateTime?metadataLocationDateTime = GetUserInputLocationDate(dataGridViewDateTime, columnIndex, null);
            if (metadataMediaDateTaken == null)
            {
                metadataMediaDateTaken = dataGridViewGenericColumn?.Metadata?.MediaDateTaken;
            }
            if (metadataLocationDateTime == null)
            {
                metadataLocationDateTime = dataGridViewGenericColumn?.Metadata?.LocationDateTime;
            }
            #endregion

            #region Get GPS Coorindates - 1. DataGridViewMap user input, 2. Metadata record 3. null
            //Get Media GPS Coordinates from DataGridViewMap is exist or use Metadata coordinates
            double?metadataLocationLatitude;
            double?metadataLocationLongitude;

            //If DataGridViewMap is agregated then pick up coordinates from what user have entered
            LocationCoordinate locationCoordinate = DataGridViewHandlerMap.GetUserInputLocationCoordinate(DataGridViewMap, null, dataGridViewGenericColumn.FileEntryAttribute);
            if (locationCoordinate != null)
            {
                metadataLocationLatitude  = locationCoordinate.Latitude;
                metadataLocationLongitude = locationCoordinate.Longitude;
            }
            else
            {
                metadataLocationLatitude  = dataGridViewGenericColumn?.Metadata?.LocationLatitude;
                metadataLocationLongitude = dataGridViewGenericColumn?.Metadata?.LocationLongitude;
            }
            #endregion


            //------------------------------------
            DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion), false);


            if (metadataLocationLatitude != null && metadataLocationLongitude != null)
            {
                TimeZoneInfo timeZoneInfoGPSLocation = TimeZoneLibrary.GetTimeZoneInfoOnGeoLocation((double)metadataLocationLatitude, (double)metadataLocationLongitude);

                if (timeZoneInfoGPSLocation != null)
                {
                    DateTime findOffsettDateTime;
                    if (metadataLocationDateTime != null)
                    {
                        findOffsettDateTime = (DateTime)metadataLocationDateTime;
                    }
                    else if (metadataLocationDateTime != null)
                    {
                        findOffsettDateTime = (DateTime)metadataMediaDateTaken;
                    }
                    else
                    {
                        findOffsettDateTime = DateTime.Now;
                    }

                    //Media header
                    DateTime       findOffsettDateTimeUTC = findOffsettDateTime.ToUniversalTime();
                    DateTimeOffset locationOffset         = new DateTimeOffset(findOffsettDateTimeUTC.Ticks, timeZoneInfoGPSLocation.GetUtcOffset(findOffsettDateTimeUTC));

                    DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerMedia, tagLocationOffsetTimeZone),
                                               TimeZoneLibrary.ToStringOffset(locationOffset.Offset) + " " + TimeZoneLibrary.TimeZoneNameStandarOrDaylight(timeZoneInfoGPSLocation, findOffsettDateTimeUTC), true, false);

                    DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerMedia, tagCalulatedOffsetZimeZone), "", true, false);

                    //
                    if (metadataLocationDateTime != null)
                    {
                        DateTime locationDateTimeUTC = ((DateTime)metadataLocationDateTime).ToUniversalTime();
                        DateTime dateTimeFromGPS     = new DateTime(locationDateTimeUTC.Ticks).Add(locationOffset.Offset);
                        DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagSuggestedLocationTime),
                                                   TimeZoneLibrary.ToStringSortable(dateTimeFromGPS) + TimeZoneLibrary.ToStringOffset(locationOffset.Offset, false), true, false);
                    }
                    else
                    {
                        DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagSuggestedLocationTime), "No GPS time found", true, false);
                    }

                    if (metadataMediaDateTaken != null)
                    {
                        DateTime       mediaTakenDateTimeUTC       = ((DateTime)metadataMediaDateTaken).ToUniversalTime();
                        DateTimeOffset mediaTakenDateTimeOffsetUTC = new DateTimeOffset(mediaTakenDateTimeUTC.Ticks, timeZoneInfoGPSLocation.GetUtcOffset(mediaTakenDateTimeUTC));

                        TimeSpan timeZoneDifferenceLocalAndLocation = timeZoneInfoGPSLocation.BaseUtcOffset - TimeZoneInfo.Local.BaseUtcOffset;
                        DateTime dateTimeUsedHomeClockOnTravel      = new DateTime(((DateTime)metadataMediaDateTaken).Ticks).Add(timeZoneDifferenceLocalAndLocation);

                        DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagWhenUsedHomeClock),
                                                   TimeZoneLibrary.ToStringSortable(dateTimeUsedHomeClockOnTravel) + TimeZoneLibrary.ToStringOffset(mediaTakenDateTimeOffsetUTC.Offset, false), true, false);

                        timeZoneDifferenceLocalAndLocation = TimeZoneInfo.Local.BaseUtcOffset - timeZoneInfoGPSLocation.BaseUtcOffset;
                        dateTimeUsedHomeClockOnTravel      = new DateTime(((DateTime)metadataMediaDateTaken).Ticks).Add(timeZoneDifferenceLocalAndLocation);
                        DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagTravelClockAtHome),
                                                   TimeZoneLibrary.ToStringSortable(dateTimeUsedHomeClockOnTravel) + TimeZoneLibrary.ToStringOffset(mediaTakenDateTimeOffsetUTC.Offset, false), true, false);
                    }
                    else
                    {
                        DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagWhenUsedHomeClock), "Can't find local time, location error", true, false);
                        DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagTravelClockAtHome), "Can't find local time, location error", true, false);
                    }
                }
                else
                {
                    DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagWhenUsedHomeClock), "Can't find local time", true, false);
                    DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagTravelClockAtHome), "Can't find local time", true, false);
                }
            }
            else
            {
                //Media header
                DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerMedia, tagLocationOffsetTimeZone), "No GPS location found", true, false);
                DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerMedia, tagCalulatedOffsetZimeZone), "No GPS location found", true, false);
                //Suggestion header
                DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagSuggestedLocationTime), "No GPS location found", true, false);
                DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagWhenUsedHomeClock), "No GPS location found", true, false);
                DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex, new DataGridViewGenericRow(headerSuggestion, tagTravelClockAtHome), "No GPS location found", true, false);
            }

            // -------------------------------------------------------
            string   timeSpanString      = "(±??:??)";
            TimeSpan?timeSpan            = TimeZoneLibrary.CalulateTimeDiffrentWithoutTimeZone(metadataMediaDateTaken, metadataLocationDateTime);
            string   prefredTimeZoneName = DataGridViewHandler.GetCellValueNullOrStringTrim(dataGridViewDateTime, columnIndex, headerMedia, tagLocationOffsetTimeZone);
            DateTime?dateTimeLocation    = null;
            if (metadataMediaDateTaken != null)
            {
                dateTimeLocation = new DateTime(((DateTime)metadataMediaDateTaken).Ticks, DateTimeKind.Utc);
            }

            string timeZoneName = TimeZoneLibrary.GetTimeZoneName(timeSpan, dateTimeLocation, prefredTimeZoneName, out string timeZoneAlternatives);

            if (timeSpan != null)
            {
                timeSpanString = TimeZoneLibrary.ToStringOffset((TimeSpan)timeSpan);
            }


            int rowIndex = DataGridViewHandler.AddRow(dataGridViewDateTime, columnIndex,
                                                      new DataGridViewGenericRow(DataGridViewHandlerDate.headerMedia, DataGridViewHandlerDate.tagCalulatedOffsetZimeZone),
                                                      timeSpanString + " " + timeZoneName, true, false);

            DataGridViewHandler.SetCellToolTipText(dataGridViewDateTime, columnIndex, rowIndex, timeZoneAlternatives);
        }
 public LocationCoordinateAndDescription()
 {
     locationCoordinate  = new LocationCoordinate();
     locationDescription = new LocationDescription();
 }
Esempio n. 18
0
 public DataGridViewGenericRow(string headerName, string rowName, LocationCoordinate locationCoordinate)
     : this(headerName, rowName, ReadWriteAccess.AllowCellReadAndWrite, false, false, null, null, null, null, locationCoordinate)
 {
 }
 public LocationCoordinateAndDescription(LocationCoordinate coordinate, LocationDescription description)
 {
     Coordinate  = coordinate;
     Description = description;
 }
Esempio n. 20
0
        private void dataGridViewMap_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex < 0)
            {
                return;
            }
            if (e.RowIndex < 0)
            {
                return;
            }

            if (isDataGridViewMaps_CellValueChanging)
            {
                return;                                       //Avoid requirng isues
            }
            if (GlobalData.IsApplicationClosing)
            {
                return;
            }

            DataGridView dataGridView = ((DataGridView)sender);

            if (!dataGridView.Enabled)
            {
                return;
            }
            if (GlobalData.IsPopulatingMapLocation)
            {
                return;
            }
            if (DataGridViewHandler.GetIsPopulatingFile(dataGridView))
            {
                return;
            }
            if (DataGridViewHandler.GetIsPopulating(dataGridView))
            {
                return;
            }


            DataGridViewGenericColumn dataGridViewGenericColumn = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridView, e.ColumnIndex);

            if (dataGridViewGenericColumn?.Metadata == null)
            {
                return;
            }
            DataGridViewGenericRow gridViewGenericRow = DataGridViewHandler.GetRowDataGridViewGenericRow(dataGridView, e.RowIndex);

            isDataGridViewMaps_CellValueChanging = true;
            ///////////////////////////////////////////////////////////////////////////
            /// Coordinate changes, updated Nomnatatim address
            ///////////////////////////////////////////////////////////////////////////
            if (gridViewGenericRow.HeaderName.Equals(DataGridViewHandlerMap.headerMedia) &&
                gridViewGenericRow.RowName.Equals(DataGridViewHandlerMap.tagMediaCoordinates))
            {
                string coordinate = DataGridViewHandler.GetCellValueNullOrStringTrim(dataGridViewMap, e.ColumnIndex, e.RowIndex);
                UpdateBrowserMap(coordinate, GetMapProvider());

                DataGridViewGenericColumn dataGridViewGenericColumnLookup = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridViewMap, e.ColumnIndex);
                AddQueueLazyLoadingMapNomnatatimLock(dataGridViewGenericColumnLookup.FileEntryAttribute, forceReloadUsingReverseGeocoder: false);

                DataGridViewHandlerDate.PopulateTimeZone(dataGridViewDate, null, dataGridViewGenericColumn.FileEntryAttribute);
            }

            ///////////////////////////////////////////////////////////////////////////
            /// Camera make and model owner changed, upated all fields
            ///////////////////////////////////////////////////////////////////////////

            else if (gridViewGenericRow.HeaderName.Equals(DataGridViewHandlerMap.headerGoogleLocations) &&
                     gridViewGenericRow.RowName.Equals(DataGridViewHandlerMap.tagCameraOwner))
            {
                string selectedCameraOwner = DataGridViewHandlerMap.GetUserInputCameraOwner(dataGridView, e.ColumnIndex);

                DataGridViewHandlerMap.SetCameraOwner(dataGridView, e.ColumnIndex, selectedCameraOwner);
                if (!string.IsNullOrWhiteSpace(selectedCameraOwner))
                {
                    if (dataGridViewGenericColumn.Metadata != null)
                    {
                        CameraOwner cameraOwner = new CameraOwner(
                            dataGridViewGenericColumn.Metadata.CameraMake,
                            dataGridViewGenericColumn.Metadata.CameraModel,
                            selectedCameraOwner);

                        databaseAndCahceCameraOwner.SaveCameraMakeModelAndOwner(cameraOwner);
                        databaseAndCahceCameraOwner.CameraMakeModelAndOwnerMakeDirty();

                        for (int columnIndex = 0; columnIndex < DataGridViewHandler.GetColumnCount(dataGridViewMap); columnIndex++)
                        {
                            DataGridViewGenericColumn gridViewGenericColumnCheck = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridView, columnIndex);

                            if (gridViewGenericColumnCheck?.Metadata == null)
                            {
                                //DEBUG
                            }
                            if (dataGridViewGenericColumn.Metadata == null)
                            {
                                //DEBUG
                            }
                            if (gridViewGenericColumnCheck?.Metadata?.CameraMake == dataGridViewGenericColumn.Metadata.CameraMake &&
                                gridViewGenericColumnCheck?.Metadata?.CameraModel == dataGridViewGenericColumn.Metadata.CameraModel)
                            {
                                DataGridViewHandlerMap.PopulateCameraOwner(dataGridView, columnIndex, gridViewGenericColumnCheck.ReadWriteAccess,
                                                                           gridViewGenericColumnCheck?.Metadata?.CameraMake, gridViewGenericColumnCheck?.Metadata?.CameraModel);
                                DataGridViewHandlerMap.PopulateGoogleHistoryCoordinateAndNearby(dataGridView, dataGridViewDate, columnIndex, GetTimeZoneShift(), GetAccepedIntervalSecound());
                            }
                        }
                    }
                }
            }

            ///////////////////////////////////////////////////////////////////////////
            /// Nomnatatim
            ///////////////////////////////////////////////////////////////////////////
            float locationAccuracyLatitude  = Properties.Settings.Default.LocationAccuracyLatitude;
            float locationAccuracyLongitude = Properties.Settings.Default.LocationAccuracyLongitude;

            if (gridViewGenericRow.HeaderName.Equals(DataGridViewHandlerMap.headerNominatim))
            {
                LocationCoordinate locationCoordinateNomnatatim = DataGridViewHandlerMap.GetUserInputLocationCoordinate(dataGridViewMap, e.ColumnIndex, null);
                bool createNewAccurateLocation = DataGridViewHandlerMap.GetUserInputIsCreateNewAccurateLocationUsingSearchLocation(dataGridViewMap, e.ColumnIndex, null);

                if (locationCoordinateNomnatatim != null)
                {
                    #region Get Coordinateds enter by user
                    LocationCoordinate locationCoordinateSearch = new LocationCoordinate(
                        (float)locationCoordinateNomnatatim.Latitude,
                        (float)locationCoordinateNomnatatim.Longitude);
                    #endregion

                    #region Get Coordinates use to store in database
                    LocationCoordinateAndDescription locationCoordinateAndDescriptionFromDatabase = databaseLocationNameAndLookUp.ReadLocationNameFromDatabaseOrCache(
                        locationCoordinateSearch, locationAccuracyLatitude, locationAccuracyLongitude);
                    #endregion

                    #region Find nearby location in Datbase
                    LocationCoordinate locationCoordinateFromDatabase;
                    if (locationCoordinateAndDescriptionFromDatabase != null && !createNewAccurateLocation)
                    {
                        locationCoordinateFromDatabase = locationCoordinateAndDescriptionFromDatabase.Coordinate; //If exist, updated
                    }
                    else
                    {
                        locationCoordinateFromDatabase = locationCoordinateSearch; //If not, create new
                    }
                    LocationCoordinateAndDescription locationCoordinateAndDescriptionUpdated =
                        new LocationCoordinateAndDescription
                        (
                            locationCoordinateSearch,
                            new LocationDescription(
                                (string)DataGridViewHandler.GetCellValue(dataGridView, e.ColumnIndex, DataGridViewHandlerMap.headerNominatim, DataGridViewHandlerMap.tagLocationName), //Name
                                (string)DataGridViewHandler.GetCellValue(dataGridView, e.ColumnIndex, DataGridViewHandlerMap.headerNominatim, DataGridViewHandlerMap.tagCity),         //City
                                (string)DataGridViewHandler.GetCellValue(dataGridView, e.ColumnIndex, DataGridViewHandlerMap.headerNominatim, DataGridViewHandlerMap.tagProvince),     //State
                                (string)DataGridViewHandler.GetCellValue(dataGridView, e.ColumnIndex, DataGridViewHandlerMap.headerNominatim, DataGridViewHandlerMap.tagCountry))      //Country
                        );
                    #endregion

                    #region Updated the database
                    databaseLocationNameAndLookUp.AddressUpdate(locationCoordinateFromDatabase,
                                                                locationCoordinateAndDescriptionUpdated, locationAccuracyLatitude, locationAccuracyLongitude);
                    #endregion

                    #region Updated DataGridView with new data
                    for (int columnIndex = 0; columnIndex < dataGridViewMap.ColumnCount; columnIndex++)
                    {
                        DataGridViewGenericColumn dataGridViewGenericColumnLookup = DataGridViewHandler.GetColumnDataGridViewGenericColumn(dataGridViewMap, columnIndex);
                        AddQueueLazyLoadingMapNomnatatimLock(dataGridViewGenericColumnLookup.FileEntryAttribute, forceReloadUsingReverseGeocoder: false);
                    }
                    #endregion
                }
            }

            isDataGridViewMaps_CellValueChanging = false;
        }
Esempio n. 21
0
        public static void GetUserInputChanges(DataGridView dataGridView, ref Metadata metadata, FileEntryAttribute fileEntryAttribute, int columnIndex = -1)
        {
            if (fileEntryAttribute == null && columnIndex == -1)
            {
                //DEBUG
                return;
            }
            if (columnIndex == -1)
            {
                columnIndex = DataGridViewHandler.GetColumnIndexUserInput(dataGridView, fileEntryAttribute);
            }
            if (columnIndex == -1)
            {
                return;                    //Column has not yet become aggregated or has already been removed
            }
            if (!DataGridViewHandler.IsColumnPopulated(dataGridView, columnIndex))
            {
                return;
            }

            LocationCoordinate.TryParse(DataGridViewHandler.GetCellValueNullOrStringTrim(dataGridView, columnIndex, headerMedia, tagMediaCoordinates), out LocationCoordinate locationCoordinate);
            metadata.LocationCoordinate = locationCoordinate;

            metadata.LocationName = (string)DataGridViewHandler.GetCellValue(dataGridView, columnIndex, headerMedia, tagLocationName);
            if (metadata.LocationName != null)
            {
                metadata.LocationName = metadata.LocationName.Trim();
            }
            if (string.IsNullOrWhiteSpace(metadata.LocationName))
            {
                metadata.LocationName = null;
            }

            metadata.LocationCity = (string)DataGridViewHandler.GetCellValue(dataGridView, columnIndex, headerMedia, tagCity);
            if (metadata.LocationCity != null)
            {
                metadata.LocationCity = metadata.LocationCity.Trim();
            }
            if (string.IsNullOrWhiteSpace(metadata.LocationCity))
            {
                metadata.LocationCity = null;
            }

            metadata.LocationState = (string)DataGridViewHandler.GetCellValue(dataGridView, columnIndex, headerMedia, tagProvince);
            if (metadata.LocationState != null)
            {
                metadata.LocationState = metadata.LocationState.Trim();
            }
            if (string.IsNullOrWhiteSpace(metadata.LocationState))
            {
                metadata.LocationState = null;
            }

            metadata.LocationCountry = (string)DataGridViewHandler.GetCellValue(dataGridView, columnIndex, headerMedia, tagCountry);
            if (metadata.LocationCountry != null)
            {
                metadata.LocationCountry = metadata.LocationCountry.Trim();
            }
            if (string.IsNullOrWhiteSpace(metadata.LocationCountry))
            {
                metadata.LocationCountry = null;
            }
        }
 /// <summary>
 /// Distances between to coordinates.
 /// </summary>
 /// <param name="coordinateA">The first position.</param>
 /// <param name="coordinateB">The second position.</param>
 /// <returns>The distance in meters between <paramref name="coordinateA"/> and <paramref name="coordinateB"/>.</returns>
 public double DistanceBetween(LocationCoordinate coordinateA, LocationCoordinate coordinateB)
 {
     return
         (new System.Device.Location.GeoCoordinate(coordinateA != null ? coordinateA.Latitude : 0, coordinateA != null ? coordinateA.Longitude : 0)
          .GetDistanceTo(new GeoCoordinate(coordinateB != null ? coordinateB.Latitude : 0, coordinateB != null ? coordinateB.Longitude : 0)));
 }
        private void PopulateMetadataLocationNames(DataGridView dataGridView, HashSet <LocationsHistory> locationsHistories, int minimumIntervalSeconds, float minimumIntervalCoordinate)
        {
            DateTime?          lastDateTime           = null;
            LocationCoordinate lastLocationCoordinate = null;

            DataGridViewHandler.SuspendLayoutSetDelay(dataGridView, true);
            foreach (LocationsHistory locationsHistory in locationsHistories)
            {
                bool isNewFund = false;
                if (lastDateTime == null || lastLocationCoordinate == null)
                {
                    isNewFund = true;
                }
                else
                {
                    bool isMinimumTimeOk     = false;
                    bool isMinimumDistanceOk = false;
                    if (Math.Abs(((DateTime)lastDateTime - locationsHistory.Timestamp).TotalSeconds) > minimumIntervalSeconds)
                    {
                        isMinimumTimeOk = true;
                    }
                    if (Math.Abs(locationsHistory.LocationCoordinate.Latitude - lastLocationCoordinate.Latitude) > minimumIntervalCoordinate)
                    {
                        isMinimumDistanceOk = true;
                    }
                    if (Math.Abs(locationsHistory.LocationCoordinate.Longitude - lastLocationCoordinate.Longitude) > minimumIntervalCoordinate)
                    {
                        isMinimumDistanceOk = true;
                    }
                    if (isMinimumTimeOk && isMinimumDistanceOk)
                    {
                        isNewFund = true;
                    }
                }

                if (isNewFund)
                {
                    lastDateTime           = locationsHistory.Timestamp;
                    lastLocationCoordinate = locationsHistory.LocationCoordinate;

                    string             group = locationsHistory.Timestamp.ToShortDateString();
                    string             rowId = locationsHistory.Timestamp.ToShortTimeString();
                    LocationCoordinate value = locationsHistory.LocationCoordinate;

                    DataGridViewHandler.AddRow(dataGridView, 0,
                                               new DataGridViewGenericRow(group),
                                               null, false, false);

                    DataGridViewHandler.AddRow(dataGridView, columnIndexTimestamp,
                                               new DataGridViewGenericRow(group, rowId, value),
                                               TimeZone.TimeZoneLibrary.ToStringSortableUTC(locationsHistory.Timestamp), true, false);

                    DataGridViewHandler.AddRow(dataGridView, columnIndexUserAccount,
                                               new DataGridViewGenericRow(group, rowId, value),
                                               locationsHistory.UserAccount, true, false);

                    DataGridViewHandler.AddRow(dataGridView, columnIndexCoordinate,
                                               new DataGridViewGenericRow(group, rowId, value),
                                               locationsHistory.LocationCoordinate.ToString(), true, false);

                    DataGridViewHandler.AddRow(dataGridView, columnIndexAltitude,
                                               new DataGridViewGenericRow(group, rowId, value),
                                               locationsHistory.Altitude, true, false);

                    DataGridViewHandler.AddRow(dataGridView, columnIndexAccuracy,
                                               new DataGridViewGenericRow(group, rowId, value),
                                               locationsHistory.Accuracy, true, false);
                }
            }
            DataGridViewHandler.ResumeLayoutDelayed(dataGridView);
            //isCellValueUpdating = false;
        }
Esempio n. 24
0
        private static int CalulateZoomLevel(LocationCoordinate locationCoordinateMin, LocationCoordinate locationCoordinateMax)
        {
            float distanceLatitude;

            if (locationCoordinateMax.Latitude < 0 && locationCoordinateMin.Latitude < 0)           // -75 <-> -50 = 25
            {
                distanceLatitude = Math.Abs(locationCoordinateMax.Latitude - locationCoordinateMin.Latitude);
            }
            else if (locationCoordinateMax.Latitude < 0 && locationCoordinateMin.Latitude >= 0)     // -50 <-> 50 = 100
            {
                distanceLatitude = Math.Abs(locationCoordinateMax.Latitude) + locationCoordinateMin.Latitude;
            }
            else if (locationCoordinateMax.Latitude >= 0 && locationCoordinateMin.Latitude < 0)     //  50 <-> -50 = 100
            {
                distanceLatitude = locationCoordinateMax.Latitude + Math.Abs(locationCoordinateMin.Latitude);
            }
            else                                                                                    //  50 <-> 75 = 25
            {
                distanceLatitude = locationCoordinateMax.Latitude - locationCoordinateMin.Latitude;
            }

            float distanceLongitude;

            if (locationCoordinateMax.Longitude < 0 && locationCoordinateMin.Longitude < 0)         // -75 <-> -50 = 25
            {
                distanceLongitude = Math.Abs(locationCoordinateMax.Longitude - locationCoordinateMin.Longitude);
            }
            else if (locationCoordinateMax.Longitude < 0 && locationCoordinateMin.Longitude >= 0)   // -50 <-> 50 = 100
            {
                distanceLongitude = Math.Abs(locationCoordinateMax.Longitude) + locationCoordinateMin.Longitude;
            }
            else if (locationCoordinateMax.Longitude >= 0 && locationCoordinateMin.Longitude < 0)   //  50 <-> -50 = 100
            {
                distanceLongitude = locationCoordinateMax.Longitude + Math.Abs(locationCoordinateMin.Longitude);
            }
            else                                                                                    //  50 <-> 75 = 25
            {
                distanceLongitude = locationCoordinateMax.Longitude - locationCoordinateMin.Longitude;
            }

            float distanceMax = Math.Max(distanceLatitude, distanceLongitude);

            int zoomLevel = 1;

            if (distanceMax < 0.01)
            {
                zoomLevel = 15;                     //OK
            }
            else if (distanceMax < 00.02)
            {
                zoomLevel = 13;
            }
            else if (distanceMax < 00.03)
            {
                zoomLevel = 12;                           //OK
            }
            else if (distanceMax < 00.40)
            {
                zoomLevel = 11;
            }
            else if (distanceMax < 00.50)
            {
                zoomLevel = 10;
            }
            else if (distanceMax < 00.60)
            {
                zoomLevel = 9;                           //0.54
            }
            else if (distanceMax < 00.80)
            {
                zoomLevel = 8;
            }
            else if (distanceMax < 01.10)
            {
                zoomLevel = 7;                           //OK
            }
            else if (distanceMax < 05.00)
            {
                zoomLevel = 6;                           //OK; Test 2.83
            }
            else if (distanceMax < 10.00)
            {
                zoomLevel = 3;
            }
            else if (distanceMax < 18.00)
            {
                zoomLevel = 3;                           //OK
            }
            else if (distanceMax < 25.00)
            {
                zoomLevel = 2;                           //OK
            }
            return(zoomLevel);
        }
 public double DistanceBetween(LocationCoordinate locationA, LocationCoordinate locationB)
 {
     return(new CLLocation(locationA != null ? locationA.Latitude : 0, locationA != null ? locationA.Longitude : 0)
            .DistanceFrom(new CLLocation(locationB != null ? locationB.Latitude : 0, locationB != null ? locationB.Longitude : 0)));
 }