Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} = this.state
const hasSearchValue = searchValue.trim().length > 0
const isPositionSet = searchLat !== null && searchLng !== null
let filteredClubs = [] // We want to show every club by default, but it'll cause a significant decrease in performance
if (searchByLocation) {
if (isPositionSet) {
const center = { latitude: searchLat, longitude: searchLng }
const conversionConstant = useImperialSystem
? MILE_TO_METER
: KILOMETER_TO_METER
const filteredPoints = getPointsInCircle(
clubs,
center,
searchRadius * conversionConstant
)
filteredClubs = geolib
.orderByDistance(center, filteredPoints)
.map(({ key }) => filteredPoints[key]) // Needed because Geolib returns a differently-shaped object
}
} else {
if (hasSearchValue) {
filteredClubs = this.fuse.search(searchValue)
}
}
return filteredClubs
}
getDelta = (selectedCoordinate: LatLng, coordinates: LatLng[]) => {
const distances = orderByDistance(selectedCoordinate, coordinates);
if (coordinates.length === 1) {
return {
longitudeDelta: 0.005,
latitudeDelta: 0.005,
};
}
// Use median to filter out extreme positions to compute more appropriate region
const lowMiddle = Math.floor((distances.length - 1) / 2);
const highMiddle = Math.ceil((distances.length - 1) / 2);
const median = (distances[lowMiddle].distance + distances[highMiddle].distance) / 2;
const validDistances =
distances.length > 2
? distances
.filter(({ distance }) => median * 1.5 > distance)
function orderResults(locationSetOriginal, point, queryDistance, withDistances, withCoordinates, withHashes, order, accurate, units) {
var orderedLocations = geolib.orderByDistance(point, locationSetOriginal);
var location;
var i;
if (accurate) {
for (i = orderedLocations.length - 1; i > -1; i--) {
if (orderedLocations[i].distance > queryDistance) {
orderedLocations = orderedLocations.slice(0, i);
break;
}
}
}
if (withHashes) {
for (i = 0; i < orderedLocations.length; i++) {
location = orderedLocations[i];
location.hash = geohash.encode_int(location.latitude, location.longitude, 52);