Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
@turf/distance
Advanced tools
@turf/distance is a module of the Turf.js library, which provides geospatial analysis tools. This specific module calculates the distance between two geographical points using various measurement units such as miles, kilometers, and degrees.
Calculate Distance in Kilometers
This feature calculates the distance between two geographical points in kilometers. The 'from' and 'to' variables represent the coordinates of the two points.
const turf = require('@turf/distance');
const from = [0, 0];
const to = [1, 1];
const options = { units: 'kilometers' };
const distance = turf(from, to, options);
console.log(distance);
Calculate Distance in Miles
This feature calculates the distance between two geographical points in miles. The 'from' and 'to' variables represent the coordinates of the two points.
const turf = require('@turf/distance');
const from = [0, 0];
const to = [1, 1];
const options = { units: 'miles' };
const distance = turf(from, to, options);
console.log(distance);
Calculate Distance in Degrees
This feature calculates the distance between two geographical points in degrees. The 'from' and 'to' variables represent the coordinates of the two points.
const turf = require('@turf/distance');
const from = [0, 0];
const to = [1, 1];
const options = { units: 'degrees' };
const distance = turf(from, to, options);
console.log(distance);
Geolib is a library to provide basic geospatial operations like distance calculation, area calculation, and more. It offers similar functionalities to @turf/distance but also includes additional features like finding the center of a cluster of points.
Geodesy is a library for geodesic calculations, including distance and bearing between points, and conversions between different coordinate systems. It provides more advanced geospatial calculations compared to @turf/distance.
Spherical Geometry is a library for performing spherical geometry calculations, including distance and area calculations on the surface of a sphere. It is similar to @turf/distance but focuses on spherical geometry.
Calculates the distance between two coordinates in degrees, radians, miles, or kilometers. This uses the Haversine formula to account for global curvature.
from
Coord origin coordinate
to
Coord destination coordinate
options
Object Optional parameters (optional, default {}
)
options.units
string can be degrees, radians, miles, or kilometers (optional, default 'kilometers'
)var from = turf.point([-75.343, 39.984]);
var to = turf.point([-75.534, 39.123]);
var options = {units: 'miles'};
var distance = turf.distance(from, to, options);
//addToMap
var addToMap = [from, to];
from.properties.distance = distance;
to.properties.distance = distance;
Returns number distance between the two coordinates
This module is part of the Turfjs project, an open source module collection dedicated to geographic algorithms. It is maintained in the Turfjs/turf repository, where you can create PRs and issues.
Install this single module individually:
$ npm install @turf/distance
Or install the all-encompassing @turf/turf module that includes all modules as functions:
$ npm install @turf/turf
FAQs
turf distance module
The npm package @turf/distance receives a total of 1,318,474 weekly downloads. As such, @turf/distance popularity was classified as popular.
We found that @turf/distance demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.