npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@shgysk8zer0/geoutils

v1.0.0

Published

Geo utils library for JavaScript

Downloads

85

Readme

geoutils

A utility library for geolocation and geohashing in JavaScript.

CodeQL Node CI Lint Code Base

GitHub license GitHub last commit GitHub release GitHub Sponsors

npm node-current npm bundle size gzipped npm

GitHub followers GitHub forks GitHub stars Twitter Follow

Donate using Liberapay


Installation

npm install @shgysk8zer0/geoutils

Usage

import { getDistance, encodeGeohash, decodeGeohash, getGeohashDistance, checkLocation, checkGeohash, getGeohashBounds, estimateGeohashAccuracy } from '@shgysk8zer0/geoutils';

// Example usage
const distance = getDistance(
  { latitude: 40.7128, longitude: -74.0060 },
  { latitude: 34.0522, longitude: -118.2437 }
);

const geohash = encodeGeohash({ latitude: 40.7128, longitude: -74.0060 });
const coordinates = decodeGeohash(geohash);
const geohashDistance = getGeohashDistance('dr5ru7', '9q5ctr');
const isWithinRadius = checkLocation(
  { latitude: 40.7128, longitude: -74.0060 },
  { latitude: 34.0522, longitude: -118.2437 },
  { radius: 5000000 }
);
const geohashBounds = getGeohashBounds('dr5ru7');
const geohashAccuracy = estimateGeohashAccuracy('dr5ru7');

API

getDistance(coords1, coords2, options)

| Parameter | Type | Description | | --- | --- | --- | | coords1 | object | Object containing latitude and longitude of the first location. | | coords1.latitude | number | Latitude of the first location. | | coords1.longitude | number | Longitude of the first location. | | coords2 | object | Object containing latitude and longitude of the second location. | | coords2.latitude | number | Latitude of the second location. | | coords2.longitude | number | Longitude of the second location. | | options | object | Optional parameters. | | options.highAccuracy | boolean | Whether to use high accuracy (Haversine formula) or lower accuracy approximation. |

Returns the distance in meters.

encodeGeohash(location, precision)

| Parameter | Type | Description | | --- | --- | --- | | location | object | Object containing latitude and longitude. | | location.latitude | number | Latitude of the location. | | location.longitude | number | Longitude of the location. | | precision | number | Desired geohash precision (length). |

Returns the geohash string.

decodeGeohash(geohash)

| Parameter | Type | Description | | --- | --- | --- | | geohash | string | The geohash to parse. |

Returns an object with latitude and longitude.

getGeohashDistance(geohash1, geohash2, options)

| Parameter | Type | Description | | --- | --- | --- | | geohash1 | string | The first geohash. | | geohash2 | string | The second geohash. | | options | object | Optional parameters. | | options.highAccuracy | boolean | Whether to use high accuracy (Haversine formula) or lower accuracy approximation. |

Returns the distance in meters.

checkLocation(location, location2, options)

| Parameter | Type | Description | | --- | --- | --- | | location | object | Object containing latitude and longitude of the target location. | | location.latitude | number | Latitude of the target location. | | location.longitude | number | Longitude of the target location. | | location2 | object | Object containing latitude and longitude of the reference location. | | location2.latitude | number | Latitude of the reference location. | | location2.longitude | number | Longitude of the reference location. | | options | object | Optional parameters. | | options.radius | number | Radius in meters to check within. | | options.highAccuracy | boolean | Whether to use high accuracy (Haversine formula) or lower accuracy approximation. |

Returns true if the location is within the specified radius, false otherwise.

checkGeohash(geohash, coords, options)

| Parameter | Type | Description | | --- | --- | --- | | geohash | string | The geohash to check against. | | coords | object | Object containing latitude and longitude of the coordinates. | | coords.latitude | number | Latitude of the coordinates. | | coords.longitude | number | Longitude of the coordinates. | | options | object | Optional parameters. | | options.highAccuracy | boolean | Whether to use high accuracy (Haversine formula) or lower accuracy approximation. | | options.radius | number | Radius in kilometers to check within. |

Returns true if the geohash is within the specified radius, false otherwise.

getGeohashBounds(geohash)

| Parameter | Type | Description | | --- | --- | --- | | geohash | string | The geohash to get bounds for. |

Returns an object with latitude and longitude bounds.

estimateGeohashAccuracy(geohash)

| Parameter | Type | Description | | --- | --- | --- | | geohash | string | The geohash to estimate accuracy for. |

Returns the estimated accuracy in meters.