How to use the geolib.getDistance 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 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 sghall / subunit / demos / data / scripts / earthquakes.js View on Github external
var sanFran = {latitude: 37.7833, longitude: -122.4167};

  var record;

  for (var i = 0; i < quakes.length; i++) {

    record = {
      dsc: quakes[i].properties.title,
      url: quakes[i].properties.url,
      mag: +quakes[i].properties.mag,
      lng: +quakes[i].geometry.coordinates[0],
      lat: +quakes[i].geometry.coordinates[1]
    };

    record.distance = geo.getDistance(record, sanFran) / 1609.34;
    recs.push(record);
  }

  recs.sort(function (a, b) { return a.distance - b.distance; });

  fs.writeFile('../../data/earthquakes.json', JSON.stringify(recs), function (err) {
    if (err) throw err;
    console.log('json saved');
  });

  json2csv({data: recs, fields: fields}, function (err, csv) {
    if (err) console.log(err);
    fs.writeFile('../../data/earthquakes.csv', csv, function (err) {
      if (err) throw err;
      console.log('csv saved');
    });
github vartan / ca-dmv-poller / poll.js View on Github external
return function(homeLocation) {
    var validDMVLocations = [];
    for (var dmvName in dmvInfo) {
      var distance = geolib.getDistance(
          {latitude: homeLocation.lat, longitude: homeLocation.lng},
          {latitude: dmvInfo[dmvName].lat, longitude: dmvInfo[dmvName].lng});
      var distanceMiles = 0.000621371 * distance;
      if (distanceMiles <= maxDistanceMiles) {
        var obj = dmvInfo[dmvName];
        obj.name = dmvName;
        obj.distanceMiles = distanceMiles;
        validDMVLocations.push(obj);
      }
    }
    return validDMVLocations;
  };
}
github hackclub / finder / src / pages / index.js View on Github external
{filteredClubs.map(club => (
            
              
            
          ))}
          {searchByLocation &&
github commonHR / commonServer / helpers / match_helpers.js View on Github external
_.each(matches, function(match) {
        var userLocation = JSON.parse(location);
        var matchLocation = JSON.parse(match.latest_location);
        var distance = (geolib.getDistance(userLocation, matchLocation)) * 0.000621371 ;//Convert to miles

        if ( distance <= searchRadius ) {
          match.distance = distance.toFixed(1);
          filteredMatches.push(match);
        }
      });
github City-of-Helsinki / open-city-app / src / util / util.js View on Github external
getDistance: function(origin = {latitude: 0.0, longitude: 0.0}, destination = {latitude: 0.0, longitude: 0.0}) {
    var distance = 0;

    if (module.exports.isNumeric(origin.latitude) && module.exports.isNumeric(origin.longitude) &&
        module.exports.isNumeric(destination.latitude) && module.exports.isNumeric(destination.latitude)) {

      distance = Geolib.getDistance(
        {latitude: origin.latitude, longitude: origin.longitude},
        {latitude: destination.latitude, longitude: destination.longitude}
      );
    }

    return distance;
  },
github jaggerwang / zqc-app-demo / src / actions / location.js View on Github external
return dispatch => {
    if (oldPosition && position &&
      geolib.getDistance(position.coords, oldPosition.coords) < 10) {
      return
    }

    dispatch({
      type: 'SET_LOCATION_POSITION',
      position
    })

    dispatch(updateLocationCity())

    oldPosition = position
  }
}
github sibbl / wohnung-scraper / app / index.js View on Github external
resultArr = resultArr.filter(item => {
          return geolib.getDistance(item, filterCenter) <= req.query.radius;
        });
      }
github arjunmehta / node-georedis / lib / interfaceEmulated.js View on Github external
var distance;

  if (order) {
    locations = orderResults(locationSetOriginal, point, queryDistance, withDistances, withCoordinates, withHashes, order, accurate, units);
  } else {
    for (locationName in locationSetOriginal) {
      location = locationSetOriginal[locationName];

      if (accurate === true) {
        distance = geolib.getDistance(point, location, 1);
        if (distance > queryDistance) {
          continue;
        }
        location.distance = convertUnitsFromMeters(units, distance);
      } else if (withDistances === true) {
        distance = geolib.getDistance(point, location, 1);
        location.distance = convertUnitsFromMeters(units, distance);
      }

      if (withHashes === true) {
        location.hash = geohash.encode_int(location.latitude, location.longitude, 52);
      }

      location.key = locationName;
      locations.push(location);
    }
  }

  if (typeof count === 'number') {
    locations = locations.slice(0, count);
  }

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 2 years ago

Package Health Score

58 / 100
Full package analysis

Similar packages