nearest-distance-calculator
v1.3.0
Published
```bash npm install nearest-distance-calculator ```
Downloads
12
Maintainers
Readme
Installation
npm install nearest-distance-calculator
Usage/Examples
JS
const { DistanceCalculator } = require("distance-calculator");
const calculator = new DistanceCalculator();
const userCoords = { lat: 37.7749, lng: -122.4194 };
const products = [
{ name: "Product 1", lat: 34.0522, lng: -118.2437 },
{ name: "Product 2", lat: 40.7128, lng: -74.006 },
];
const nearestProduct = calculator.suggestNearestProduct(userCoords, products);
console.log(nearestProduct);
Ts (TypeScript)
import {
DistanceCalculator,
Coordinates,
DistanceProduct,
} from "distance-calculator";
const calculator = new DistanceCalculator();
const userCoords: Coordinates = { lat: 37.7749, lng: -122.4194 };
const products: DistanceProduct[] = [
{ name: "Product 1", lat: 34.0522, lng: -118.2437 },
{ name: "Product 2", lat: 40.7128, lng: -74.006 },
];
const nearestProduct = calculator.suggestNearestProduct(userCoords, products);
console.log(nearestProduct);