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

hero-geo-location

v1.0.2

Published

A CLI tool to get geographical coordinates from an address

Downloads

12

Readme

Hero Geo Location CLI

Hero Geo Location CLI is a simple command-line tool to get geographical coordinates (latitude and longitude) from an address, get an address from coordinates, or search for locations using the Nominatim OpenStreetMap API.

Installation

To install the package globally, run:

npm install -g hero-geo-location

To use the package in your JavaScript project, run:

npm install hero-geo-location

Usage

CLI

To get the geographical coordinates of an address, use the following command:

geo "country,city,street,zipcode"

To get the address from geographical coordinates, use the following command:

geo <lat> <lon>

To search for locations using a query, use the following command:

geo search "query"

JavaScript Module

To get the geographical coordinates of an address in your JavaScript code, use the following code:

const {
  getGeoLocation,
  getReverseGeoLocation,
  searchLocation,
} = require("hero-geo-location");

// Forward geocoding
getGeoLocation("country,city,street,zipcode")
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });

// Reverse geocoding
getReverseGeoLocation(lat, lon)
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });

// Search locations
searchLocation("query")
  .then((results) => {
    console.log(results);
  })
  .catch((error) => {
    console.error(error);
  });

Examples

CLI Example

Forward Geocoding

geo "USA, New York, 5th Avenue, 10001"

Output:

{
  "latitude": "40.7127281",
  "longitude": "-74.0060152",
  "address": "5th Avenue, New York, NY 10001, USA",
  "type": "road",
  "name": "5th Avenue, New York, NY 10001, USA",
  "country": "United States",
  "city": "New York",
  "country_code": "us",
  "boundingbox": ["40.7127281", "40.7127281", "-74.0060152", "-74.0060152"]
}

Reverse Geocoding

geo -34.44076 -58.70521

Output:

{
  "latitude": "-34.44076",
  "longitude": "-58.70521",
  "address": "Some address in Buenos Aires, Argentina",
  "type": "place",
  "name": "Some address in Buenos Aires, Argentina",
  "country": "Argentina",
  "city": "Buenos Aires",
  "country_code": "ar",
  "boundingbox": ["-34.44076", "-34.44076", "-58.70521", "-58.70521"]
}

Search Location

geo search "rewe Bahnhofstraße berlin"

Output:

[
  {
    "latitude": "52.4586902",
    "longitude": "13.5772772",
    "address": "REWE, 33-38, Bahnhofstraße, Dammvorstadt, Köpenick, Treptow-Köpenick, Berlin, 12555, Deutschland",
    "type": "supermarket",
    "name": "REWE, 33-38, Bahnhofstraße, Dammvorstadt, Köpenick, Treptow-Köpenick, Berlin, 12555, Deutschland",
    "country": "Deutschland",
    "city": "Berlin",
    "country_code": "de",
    "boundingbox": ["52.4585902", "52.4587902", "13.5771772", "13.5773772"]
  },
  {
    "latitude": "52.4577394",
    "longitude": "13.5789184",
    "address": "REWE City, 23-25, Bahnhofstraße, Dammvorstadt, Köpenick, Treptow-Köpenick, Berlin, 12555, Deutschland",
    "type": "supermarket",
    "name": "REWE City, 23-25, Bahnhofstraße, Dammvorstadt, Köpenick, Treptow-Köpenick, Berlin, 12555, Deutschland",
    "country": "Deutschland",
    "city": "Berlin",
    "country_code": "de",
    "boundingbox": ["52.4576394", "52.4578394", "13.5788184", "13.5790184"]
  }
]

JavaScript Example

const {
  getGeoLocation,
  getReverseGeoLocation,
  searchLocation,
} = require("hero-geo-location");

// Forward geocoding
getGeoLocation("Germany, Berlin, Unter den Linden, 10117")
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });

// Reverse geocoding
getReverseGeoLocation(-34.44076, -58.70521)
  .then((result) => {
    console.log(result);
  })
  .catch((error) => {
    console.error(error);
  });

// Search locations
searchLocation("Unter den Linden 1 Berlin")
  .then((results) => {
    console.log(results);
  })
  .catch((error) => {
    console.error(error);
  });

Author

Milad Davoodabadi

License

ISC