Exemple #1
0
        public MapBounds GetBoundsForNearestVehicles(bool isUsingGeoServices, Address pickup, IEnumerable <AvailableVehicle> cars)
        {
            if (cars == null || !cars.Any() || !_settings.Data.ZoomOnNearbyVehicles)
            {
                return(null);
            }

            var radius       = _settings.Data.ZoomOnNearbyVehiclesRadius;
            var vehicleCount = _settings.Data.ZoomOnNearbyVehiclesCount;

            var centerLatitude  = pickup.Latitude;
            var centerLongitude = pickup.Longitude;

            var vehicles = OrderVehiclesByDistanceIfNeeded(isUsingGeoServices, pickup, cars)
                           .Where(car => Position.CalculateDistance(car.Latitude, car.Longitude, centerLatitude, centerLongitude) <= radius)
                           .Take(vehicleCount)
                           .ToArray();

            if (!vehicles.Any())
            {
                return(null);
            }

            var distanceFromLastVehicle = Position.CalculateDistance(vehicles.Last().Latitude, vehicles.Last().Longitude, centerLatitude, centerLongitude);

            var maximumBounds = MapBounds.GetBoundsFromCenterAndRadius(centerLatitude, centerLongitude, distanceFromLastVehicle, distanceFromLastVehicle);

            return(maximumBounds);
        }
        public async Task <GeoAddress[]> GeocodeAddressAsync(string query, string currentLanguage, double?pickupLatitude, double?pickupLongitude, double searchRadiusInMeters)
        {
            // Do nothing with currentLanguage parameter since Android Geocoder
            // automatically gets the results using the system language
            var geocoder = new Geocoder(_androidGlobals.ApplicationContext);

            Position lowerLeft  = null;
            Position upperRight = null;

            if (!query.ToLowerInvariant().Contains("bounds=") &&
                pickupLatitude.HasValue && pickupLongitude.HasValue &&
                pickupLatitude.Value != 0 && pickupLatitude.Value != 0)
            {
                // Note that biasing only prefers results within the bounds; if more relevant results exist outside of these bounds, they may be included.
                var mapBounds = MapBounds.GetBoundsFromCenterAndRadius(pickupLatitude.Value, pickupLongitude.Value, searchRadiusInMeters, searchRadiusInMeters);
                lowerLeft = new Position {
                    Latitude = mapBounds.SouthBound, Longitude = mapBounds.WestBound
                };
                upperRight = new Position {
                    Latitude = mapBounds.NorthBound, Longitude = mapBounds.EastBound
                };
            }

            var locationsTask = lowerLeft != null && upperRight != null
                ? geocoder.GetFromLocationNameAsync(query.Replace("+", " "), 100, lowerLeft.Latitude, lowerLeft.Longitude, upperRight.Latitude, upperRight.Longitude)
                : geocoder.GetFromLocationNameAsync(query.Replace("+", " "), 100);

            try
            {
                var locations = await locationsTask;

                return(locations.Select(ConvertAddressToGeoAddress).ToArray());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex);
                return(new GeoAddress[0]);
            }
        }