Exemple #1
0
        public IEnumerable <SongDistance> GetNearSongs(double latitude, double longitude, int styleId)
        {
            var songsFromAmbassadors = _context.Historics
                                       .Include(x => x.User)
                                       .Include(x => x.Song).ThenInclude(x => x.Artist)
                                       .Where(x => x.LikeType == LikeType.Ambassador && x.Song.StyleSongs.Any(y => y.StyleID == styleId))
                                       .Select(x => new SongDistance
            {
                Song     = x.Song,
                Distance = Math.Round(DistanceHelper.CalculateDistance(latitude, longitude, x.User.LastGeoCoordinate.Latitude, x.User.LastGeoCoordinate.Longitude), 1)
            })
                                       .ToList();

            var nearSongs = _context.Songs
                            .Include(x => x.Artist).ThenInclude(x => x.GeoCoordinate)
                            .Include(x => x.Historics)
                            .Include(x => x.StyleSongs)
                            .Where(x => x.StyleSongs.Any(y => y.StyleID == styleId))
                            .Select(x => new SongDistance
            {
                Song     = x,
                Distance = Math.Round(DistanceHelper.CalculateDistance(latitude, longitude, x.Artist.GeoCoordinate.Latitude, x.Artist.GeoCoordinate.Longitude), 1)
            })
                            .ToList();

            var result = nearSongs
                         .Concat(songsFromAmbassadors)
                         .OrderBy(x => x.Distance)
                         .GroupBy(x => x.Song.ID)
                         .Select(g => g.First())
                         .ToList();

            return(result);
        }
        public double GetCurrentDistance(Location currentLocation)
        {
            if (currentLocation.Speed != 0)
            {
                double lastLeg = 0;
                if (LastKnownLocation == null)
                {
                    lastLeg           = DistanceHelper.CalculateDistance(InitialLocation, currentLocation);
                    LastKnownLocation = currentLocation;
                }
                else
                {
                    lastLeg = DistanceHelper.CalculateDistance(LastKnownLocation, currentLocation);
                }
                CurrentDistance = CurrentDistance + lastLeg;
            }

            return(CurrentDistance);
        }
Exemple #3
0
        private List <Place> GetNearPlaces(List <Place> allPlaces, LatLng userLocation)
        {
            var lat            = userLocation.Latitude;
            var lng            = userLocation.Longitude;
            var nearPlacesList = new List <Place>();

            foreach (Place place in allPlaces)
            {
                var placeLat = place.Lat;
                var placeLng = place.Lng;
                var distance = DistanceHelper.CalculateDistance(lat, lng, placeLat, placeLng);
                if (distance <= 0.5)
                {
                    nearPlacesList.Add(place);
                }
            }

            nearPlacesList.OrderByDescending(o => o.Rating);
            return(nearPlacesList);
        }
Exemple #4
0
        private void AddMarkers(string category)
        {
            _googleMap.Clear();
            LatLng userLatLng = new LatLng(_userLat, _userLng);

            AddUserMarker(userLatLng);

            _selectedPlaces = _placeDatabase.GetAllPlacesByCategory(category);

            foreach (Place place in _selectedPlaces)
            {
                LatLng placeLatLng = new LatLng(place.Lat, place.Lng);
                double distance    = Math.Round(DistanceHelper.CalculateDistance(GetLastKnownLocation().Latitude, GetLastKnownLocation().Longitude, place.Lat, place.Lng), 2);

                var placeMarker = new MarkerOptions();
                placeMarker.SetPosition(placeLatLng)
                .SetTitle(place.Name)
                .SetSnippet("rating: " + place.Rating.ToString() + ", vzdialené: " + distance.ToString() + "km")
                .SetIcon(BitmapDescriptorFactory.FromResource(GetIconByCategory(place.Category)));
                _googleMap.AddMarker(placeMarker);
            }
        }
Exemple #5
0
        public override async void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
        {
            if (holder is PlaceViewHolder placeViewHolder)
            {
                placeViewHolder.PlaceNameTextView.Text   = _places[position].Name;
                placeViewHolder.PlaceRatingTextView.Text = _places[position].Rating.ToString();

                LatLng userLatLng = await GetLocation();

                double distance = Math.Round(DistanceHelper.CalculateDistance(userLatLng.Latitude, userLatLng.Longitude, _places[position].Lat, _places[position].Lng), 2);
                placeViewHolder.PlaceDistanceTextView.Text = distance.ToString() + " km";

                if (_places[position].Photo.Length <= 1)
                {
                    int imageId = (int)typeof(Resource.Drawable).GetField("no_image").GetValue(null);
                    placeViewHolder.PlaceImageView.SetImageResource(imageId);
                }
                else
                {
                    var imageBitmap = ImageHelper.GetImageBitmapFromUrl(_places[position].Photo);
                    placeViewHolder.PlaceImageView.SetImageBitmap(imageBitmap);
                }
            }
        }