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

pepe-distcalc

v0.9.3

Published

Calculate the distance between two coordinates

Downloads

12

Readme

pepe-distcalc

A geographical distance calculator. It calculates the distance between two geographic points and identifies the country, address, zipcode, city of origin and destination. It also calculates the distance in a straight line between the two points in kilometers and nautical miles.
A geographical points identifier. You enter the geographic coordinate of a point and it returns the country, address, zipcode and city.

Installation

Install using npm:

$ npm i pepe-distcalc

Usage examples

A geographical distance calculator

Search by coordinates

Accepted two types of coordinates

	/**
	 * supported formats
	 *  (DMS): 41°24'12"N 2°10'26"E
	 *  (DD): 41.40338 2.17403
	 * Decimal separator "."
	 * No decimals accepted in format DMS
	 */

The quotes that belong to the seconds, can be a double or two simple

	41°24'12"N 2°10'26"E
			or
	41°24'12''N 2°10'26''E
	

Always between latitude and longitude in both formats, you must leave a space.

Example 1
coordToDistance(coordInit,coordEnd,type)

const distCalc = require('pepe-distcalc')

const tests0 = async (coordInit,coordEnd,type)=>{
    try {
        const coorDist = await distCalc.coordToDistance(coordInit,coordEnd,type)
        console.log('The result is: ',coorDist);
        
    } catch (error) {
        console.error(error)
    };   
};

//example coordenates type 'DMS'
tests0(`41°37'03"N 0°37'47"E`,`40°31'33"N 3°23'27"W`,'DMS');

//example coordinates type DD
tests0("41.40333333333333 2.1738888888888885","41.39333333333333 2.1738888888888885","DD")

The result is:

The result is:  {
  coordOr: { lat: 41.4034789, lon: 2.174410333009705 },
  cityO: 'Barcelona',
  countryO: 'España',
  zipcodeO: '08001',
  streetNameO: 'Carrer de Mallorca',
  coordDest: { lat: 41.3933595, lon: 2.1739429 },
  cityE: 'Barcelona',
  countryE: 'España',
  zipcodeE: '08001',
  streetNameE: 'Gran Via de les Corts Catalanes',
  provider: 'openstreetmap',
  distanceKM: '1.1',
  distanceNM: '0.6'
}

Search by Country and Zip code

Searches can also be done by country and zip code

Example 2
codPostToDistance(country1,zipCode1,country2,zipCode2)

const distCalc = require('pepe-distcalc')

const test2 = async (country1,zipCode1,country2,zipCode2) =>{
	try{
    	const zipDist = await distCalc.codPostToDistance(country1,zipCode1,country2,zipCode2)
    	console.log('The result is: ',zipDist);
	} catch (error) {
    	return error;
	};
};

//Example country and zip code
test2('Spain','08210','Spain','41001')

The result is:

The result is:  {
  coordOr: { lat: 41.5166373621772, lon: 2.1274182947644396 },
  cityO: 'Barberà del Vallès',
  countryO: 'España',
  zipcodeO: '08210',
  streetNameO: undefined,
  coordDest: { lat: 37.3883271650025, lon: -5.995913806931262 },
  cityE: 'Sevilla',
  countryE: 'España',
  zipcodeE: '41001',
  streetNameE: undefined,
  provider: 'openstreetmap',
  distanceKM: '834.4',
  distanceNM: '450.5'
}

A geographical points identifier

Search by coordinates

Accepted two types of coordinates

	/**
	 * supported formats
	 *  (DMS): 41°24'12"N 2°10'26"E
	 *  (DD): 41.40338 2.17403
	 * Decimal separator "."
	 * No decimals accepted in format DMS
	 */

The quotes that belong to the seconds, can be a double or two simple

	41°24'12"N 2°10'26"E
			or
	41°24'12''N 2°10'26''E
	

Always between latitude and longitude in both formats, you must leave a space.

Example 3
coordToLocation(coord,'DMS')

const distCalc = require('pepe-distcalc')

const test3 = async (coord,type) =>{
    try {
        const coorPos = await distCalc.coordToLocation(coord,type)
        console.log('The result is: ',coorPos);
    } catch (error) {
        console.error(error)
    }
};

//example coordenates type 'DMS'
test3(`41°37'03"N 0°37'47"E`,'DMS');
//example coordenates type 'DMS'
test3("41.40333333333333 2.1738888888888885","DD")

The result is:

The result is:  {
  coord: { lat: 41.4034789, lon: 2.174410333009705 },
  city: 'Barcelona',
  country: 'España',
  zipcode: '08001',
  streetName: 'Carrer de Mallorca',
  provider: 'openstreetmap'
}

Search by Country and Zip code

Searches can also be done by country and zip code Example 4
codPostToLocation(country,zipCode)

const distCalc = require('pepe-distcalc')

const test4 = async (country,zipCode) =>{
    try {
        const zipPos = await distCalc.codPostToLocation(country,zipCode);
        console.log('The result is: ',zipPos);
    } catch (error) {
        console.error(error);
    }    
};

//Example country and zip code
test4('Spain','08210');

The result is:

The result is:  {
  coord: { lat: 41.5166373621772, lon: 2.1274182947644396 },
  city: 'Barberà del Vallès',
  country: 'España',
  zipcode: '08210',
  streetName: undefined,
  provider: 'openstreetmap'
}

pepe-distcalc providers

  1. node-geoceoder link.
  2. openstreetmap : OpenStreetMapGeocoder. Supports address geocoding and reverse geocoding. You can use options.language and options.email to specify a language and a contact email address. For geocode, you can use an object as value, specifying one or several parameters For reverse, you can use additional parameters You should specify a specific user-agent or referrer header field as required by the OpenStreetMap Usage Policy Set options.osmServer to use custom nominatim server. Example: you can setup local nominatim server by following these instructions and set options.osmServer: http://localhost:8000 to use local server.