How to use geolib - 10 common examples

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 flyandi / react-native-maps-navigation / src / modules / Simulator.js View on Github external
points.forEach((point, index) => {

            const nextPoint = points[index + 1];

            if(nextPoint && !nextPoint.final == true) {

                // calculate distance between each point
                const distance = Math.round(GeoLib.getDistance(point, nextPoint));
                const bearing =  GeoLib.getBearing(point, nextPoint);

                if(bearing !== 0) {

                    if (distance > 1) {

                        for (var x = 1; x < distance; x++) {

                            result.push(Object.assign({}, {bearing}, GeoLib.computeDestinationPoint(point, x, bearing)));
                        }

                    } else {
                        result.push(Object.assign({}, {bearing}, point));
                    }
                }
            }
github NetsBlox / NetsBlox / utils / rpc / eclipse-2017 / checkStations.js View on Github external
function distanceToPath(lat, lon){
    let min = 100000; //in KM
    let poi = {latitude: lat, longitude: lon};
    for (var i = 0; i < pathPoints.length; i++) {
        let dist = geolib.getDistance(poi, {latitude: pathPoints[i][0], longitude: pathPoints[i][1]}) / 1000;
        if (dist > min) break;
        min = dist;
    }
    return min; //in KM
}
/* eslint-enable no-console */
github team-copper / captAR / component / Map.js View on Github external
onCapturePress() {

    let team = '';

    for (let i=0; i
github flyandi / react-native-maps-navigation / src / modules / Simulator.js View on Github external
points.forEach((point, index) => {

            const nextPoint = points[index + 1];

            if(nextPoint && !nextPoint.final == true) {

                // calculate distance between each point
                const distance = Math.round(GeoLib.getDistance(point, nextPoint));
                const bearing =  GeoLib.getBearing(point, nextPoint);

                if(bearing !== 0) {

                    if (distance > 1) {

                        for (var x = 1; x < distance; x++) {

                            result.push(Object.assign({}, {bearing}, GeoLib.computeDestinationPoint(point, x, bearing)));
                        }

                    } else {
                        result.push(Object.assign({}, {bearing}, point));
                    }
                }
            }
        });
github flyandi / react-native-maps-navigation / src / modules / Tools.js View on Github external
const d2r = Math.PI / 180;   // degrees to radians
    const r2d = 180 / Math.PI;   // radians to degrees
    const points = 32;
    let result = [];

    // find the radius in lat/lon
    //const rlat = (radius / EARTH_RADIUS_METERS) * r2d;
    //const rlng = rlat / Math.cos({coordinate.latitude * d2r);

    if (initialBearing > finalBearing) finalBearing += 360;
    let deltaBearing = finalBearing - initialBearing;
    deltaBearing = deltaBearing/points;

    for (let i=0; (i < points+1); i++)
    {
        result.push(geolib.computeDestinationPoint(coordinate, radius, initialBearing + i*deltaBearing));
    }

    return result;
};
github vokkim / tuktuk-chart-plotter / src / client / map.js View on Github external
function calculateExtensionLine(position, course, speed, extensionLineSetting) {
  if (extensionLineSetting === EXTENSION_LINE_OFF) {
    return undefined
  }
  const time = 60 * parseInt(extensionLineSetting)
  if (position && position.latitude && position.longitude && course && speed > 0.5) {
    const distance = speed * time // Speed in m/s
    const start = [position.latitude, position.longitude]
    const destination = computeDestinationPoint(
      {lat: position.latitude, lon: position.longitude},
      distance,
      toDegrees(course)
    )
    const middle = computeDestinationPoint(
      {lat: position.latitude, lon: position.longitude},
      distance / 2,
      toDegrees(course)
    )
    return {
      start,
      middle: [middle.latitude, middle.longitude],
      end: [destination.latitude, destination.longitude]
    }
  }
  return undefined
}
github vokkim / tuktuk-chart-plotter / src / client / map.js View on Github external
function calculateExtensionLine(position, course, speed, extensionLineSetting) {
  if (extensionLineSetting === EXTENSION_LINE_OFF) {
    return undefined
  }
  const time = 60 * parseInt(extensionLineSetting)
  if (position && position.latitude && position.longitude && course && speed > 0.5) {
    const distance = speed * time // Speed in m/s
    const start = [position.latitude, position.longitude]
    const destination = computeDestinationPoint(
      {lat: position.latitude, lon: position.longitude},
      distance,
      toDegrees(course)
    )
    const middle = computeDestinationPoint(
      {lat: position.latitude, lon: position.longitude},
      distance / 2,
      toDegrees(course)
    )
    return {
      start,
      middle: [middle.latitude, middle.longitude],
      end: [destination.latitude, destination.longitude]
    }
  }
  return undefined
github flyandi / react-native-maps-navigation / src / modules / Simulator.js View on Github external
const nextPoint = points[index + 1];

            if(nextPoint && !nextPoint.final == true) {

                // calculate distance between each point
                const distance = Math.round(GeoLib.getDistance(point, nextPoint));
                const bearing =  GeoLib.getBearing(point, nextPoint);

                if(bearing !== 0) {

                    if (distance > 1) {

                        for (var x = 1; x < distance; x++) {

                            result.push(Object.assign({}, {bearing}, GeoLib.computeDestinationPoint(point, x, bearing)));
                        }

                    } else {
                        result.push(Object.assign({}, {bearing}, point));
                    }
                }
            }
        });
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)

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 11 months ago

Package Health Score

76 / 100
Full package analysis

Similar packages