GithubHelp home page GithubHelp logo

offline-geocoder's Introduction

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.

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 my meager laptop I can perform around 300 lookups per second with a single process.

Installation

npm install --save offline-geocoder

You also need to obtain a database which isn't included in the package, to generate your own take a look in scripts.

Usage

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

const geocoder = require('offline-geocoder')({ database: 'data/geodata.db' })

Reverse Geocoding

To perform a revese geocode lookup just pass the coordinates:

geocoder.reverse(41.89, 12.49)
  .then(function(result) {
    console.log(result)
  })
  .catch(function(error) {
    console.error(error)
  })

Which outputs:

{ id: 3169070,
  name: 'Rome',
  formatted: 'Rome, Latium, Italy',
  country: { id: 'IT', name: 'Italy' },
  admin1: { id: 7, name: 'Latium' },
  coordinates: { latitude: 41.89193, longitude: 12.51133 } }

The library also has a callback interface:

geocoder.reverse(41.89, 12.49, function(error, result) {
  console.log(result)
})

License

This library is licensed under the MIT license.

You don't need to give this library attribution, but you must do so for GeoNames if you use their data!

offline-geocoder's People

Contributors

cosorio94 avatar lucaspiller avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

offline-geocoder's Issues

Error in SQL retrieval

TypeError: Cannot read property 'id' of undefined
    at formatResult (project/app/node-app/node_modules/offline-geocoder/src/reverse.js:55:11)
    at Statement.<anonymous> (project/app/node-app/node_modules/offline-geocoder/src/reverse.js:41:24)
--> in Database#all('SELECT * FROM everything WHERE id IN (\n                     SELECT feature_id\n                     FROM coordinates\n                     WHERE latitude BETWEEN $lat - 1.5 AND $lat + 1.5\n                     AND longitude BETWEEN $lon - 1.5 AND $lon + 1.5\n                     ORDER BY (\n                       ($lat - latitude) * ($lat - latitude) +\n                         ($lon - longitude) * ($lon - longitude) * $scale\n                     ) ASC\n                     LIMIT 1\n                   )', { '$lat': undefined, '$lon': undefined, '$scale': NaN }, [Function])
    at project/app/node-app/node_modules/offline-geocoder/src/reverse.js:29:17
    at new Promise (<anonymous>)
    at findFeature (project/app/node-app/node_modules/offline-geocoder/src/reverse.js:14:10)
    at Reverse (project/app/node-app/node_modules/offline-geocoder/src/reverse.js:90:10)
    at geocoder.Geocoder.geocoder.reverse (project/app/node-app/node_modules/offline-geocoder/src/index.js:19:12)

sqlite3 dependency no longer current

Version 4 of sqlite3 has building issues using the current node (version 14.17.0 LTS) toolchain, on Windows. Current sqlite3 (version 5.0.2) has resolved those issues.

I propose updating the dependency reference in package.json to use the newer version

Release latest version on npm

Can you release it, please?

The current version (1.0.0) has multiple vulnerabilities because of sqlite3:

✗ Medium severity vulnerability found in stringstream
  Description: Uninitialized Memory Exposure
  Info: https://snyk.io/vuln/npm:stringstream:20180511
  Introduced through: [email protected]
  From: [email protected] > [email protected] > [email protected] > [email protected] > [email protected]
  Remediation:
    Your dependencies are out of date, otherwise you would be using a newer version of stringstream.
    Try deleting node_modules, reinstalling and running `snyk test` again. If the problem persists, one of your dependencies may be bundling outdated modules.

✗ Medium severity vulnerability found in cryptiles
  Description: Insecure Randomness
  Info: https://snyk.io/vuln/npm:cryptiles:20180710
  Introduced through: [email protected], [email protected], [email protected]
  From: [email protected]
  From: [email protected] > [email protected]
  From: [email protected] > [email protected] > [email protected] > [email protected] > [email protected]
  and 1 more...
  Remediation:
    Upgrade direct dependency [email protected] to [email protected] (triggers upgrades to [email protected])
    Upgrade direct dependency [email protected] to [email protected] (triggers upgrades to [email protected] > [email protected])
    Some paths have no direct dependency upgrade that can address this issue. Run `snyk wizard` to explore remediation options.

✗ High severity vulnerability found in sshpk
  Description: Regular Expression Denial of Service (ReDoS)
  Info: https://snyk.io/vuln/npm:sshpk:20180409
  Introduced through: [email protected]
  From: [email protected] > [email protected] > [email protected] > [email protected] > [email protected] > [email protected]
  Remediation:
    Your dependencies are out of date, otherwise you would be using a newer version of sshpk.
    Try deleting node_modules, reinstalling and running `snyk test` again. If the problem persists, one of your dependencies may be bundling outdated modules.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.