How to use the geolib.orderByDistance function in geolib

To help you get started, we’ve selected a few geolib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hackclub / finder / src / pages / index.js View on Github external
} = 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
  }
github kiwicom / mobile / app / hotels / src / map / allHotels / MapView.js View on Github external
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)
github arjunmehta / node-georedis / lib / interfaceEmulated.js View on Github external
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);

geolib

Library to provide basic geospatial operations like distance calculation, conversion of decimal coordinates to sexagesimal and vice versa, etc. This library is currently **2D**, meaning that altitude/elevation is not yet supported by any of its functions!

MIT
Latest version published 1 year ago

Package Health Score

62 / 100
Full package analysis