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

@treblefm/offline-geocoder

v1.0.0

Published

Node library for reverse geocoding. Designed to be used offline (for example embedded in a desktop or mobile application) - no web requests are made to perform a lookup.

Downloads

4

Readme

Offline Geocoder

Node library for reverse geocoding. Designed to be used offline (for example embedded in a desktop or mobile application) - no web requests are made to perform a lookup.

Data

This uses data from the GeoNames project, which is free to use under the Creative Commons Attribution 3.0 license. To enable this to work offline, the data is imported into a SQLite database which is roughly 12 MB, so easily embeddable within an application. If you use this data, you must give attribution, as specified by the license.

By default it uses the cities1000 dataset which contains details of all worldwide cities with a population of at least 1000 people. Depending on your needs you may get better performance or accuracy by using one of their other datasets.

The GeoNames data is limited to city-level granularity, so if you need street level accuracy this won't work for you. Also most data is only available in English. Take a look at the OpenStreetMap Nominatim project for a similar tool with a lot more features.

The advantages of this working offline are you don't need to pay or obtain a license key, and it's fast. On a 2015 MacBook Pro, the geocoder-benchmark tool achieves ~540 lookups per second using the cities1000 dataset.

Installation

npm install --save @treblefm/offline-geocoder

A database with the latest data will be generated automatically as a postinstall step. An internet connection is required for this succeed.

Usage

When you initialize the library you need to pass the location of the database:

const Geocoder = require("offline-geocoder");
let geocoder = new Geocoder({ database: "data/geodata.sqlite" });

Reverse Geocoding

To perform a reverse geocode lookup just pass the coordinates:

geocoder.reverse(41.89, 12.49)
  .then((result) => {
    console.log(JSON.stringify(result, null, 2));
    process.exit(0);
  })
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

Which outputs:

{
  "formatted": "Rome, Latium, Italy",
  "city": {
    "id": 3169070,
    "name": "Rome"
  },
  "region": {
    "id": 7,
    "name": "Latium"
  },
  "country": {
    "id": "IT",
    "name": "Italy"
  },
  "coordinates": {
    "latitude": 41.89193,
    "longitude": 12.51133
  }
}

License

This library is licensed under the MIT license.