diff --git a/.jshintrc b/.jshintrc
index ba6d0c2..0d8d561 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -4,5 +4,5 @@
"node": true,
"loopfunc": true,
"expr": true,
- "esversion": 6
+ "esversion": 11
}
diff --git a/README.md b/README.md
index ce0fee4..8b5a8bc 100644
--- a/README.md
+++ b/README.md
@@ -76,7 +76,7 @@ geocoder.init(
);
```
-Optionally `init()` allows you to specify the directory that geonames files are
+Optionally `init()` allows you to specify the directory that GeoNames files are
downloaded and cached in, and a specific cities database to be used.
```javascript
@@ -330,9 +330,9 @@ of disk space). All follow-up requests are lightning fast.
### Downloading specific sets of countries
To reduce the time taken to initialize the data, you can manually configure it
-to only download a specific set of countries from Geonames. Do note that when
+to only download a specific set of countries from GeoNames. Do note that when
you add a country code into the array, it will disable the geocoder from
-downloading all ~2GB(!) worth of data and only load the specified countries'
+downloading all ~2.29GB(!) worth of data and only load the specified countries'
data. If you want to re-enable the geocoder to download all data, the countries
array needs to be empty.
@@ -359,10 +359,10 @@ geocoder.init(
### Post-install script
-There's also the option of downloading the Geonames files via a post-install
-script.
+There's also the option of downloading the GeoNames files via a post-install
+script.
The script is invoked automatically after installation, but won't download any
-files without getting at least one of the init options in an env variable.
+files without getting at least one of the init options in an env variable.
The options should be specified with a `GEOCODER_POSTINSTALL_` prefix.
#### Example of downloading the files via the post-install script
@@ -417,8 +417,8 @@ specific language governing permissions and limitations under the License.
## Acknowledgements
This project was inspired by Richard Penman's Python
-[reverse geocoder](https://github.com/richardpenman/reverse_geocode/). It
-uses Ubilabs'
+[reverse geocoder](https://github.com/richardpenman/reverse_geocode/). It uses
+Ubilabs'
[k-d-tree implementation](https://github.com/ubilabs/kd-tree-javascript) that
was ported to Node.js by [Luke Arduini](https://github.com/luk-/node-kdt).
diff --git a/app.js b/app.js
index 568cb73..b56b412 100644
--- a/app.js
+++ b/app.js
@@ -55,7 +55,7 @@ app.listen(port, function () {
console.log('Local reverse geocoder listening on port ' + port);
console.log('Initializing Geocoder…');
console.log(
- '(This may take a long time and will download ~300MB worth of data.)'
+ '(This may take a long time and will download ~2.29GB worth of data by default.)'
);
geocoder.init(
{
diff --git a/app.ts b/app.ts
index e88ae1d..7a3dfc7 100644
--- a/app.ts
+++ b/app.ts
@@ -67,7 +67,7 @@ app.listen(port, function () {
console.log('Local reverse geocoder listening on port ' + port);
console.log('Initializing Geocoder…');
console.log(
- '(This may take a long time and will download ~300MB worth of data.)'
+ '(This may take a long time and will download ~2.29GB worth of data by default.)'
);
geocoder.init(
diff --git a/docs/global.html b/docs/global.html
index 08a1d15..04448a3 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -169,7 +169,8 @@
Parameters:
-
One single or an array of
latitude/longitude pairs
+
One single or an array of
+ latitude/longitude pairs
@@ -296,7 +297,20 @@
Returns:
Example
-
// With just one point
var point = {latitude: 42.083333, longitude: 3.1};
geocoder.lookUp(point, 1, function(err, res) {
console.log(JSON.stringify(res, null, 2));
});
// In batch mode with many points
var points = [
{latitude: 42.083333, longitude: 3.1},
{latitude: 48.466667, longitude: 9.133333}
];
geocoder.lookUp(points, 1, function(err, res) {
console.log(JSON.stringify(res, null, 2));
});
+
// With just one point
+var point = {latitude: 42.083333, longitude: 3.1};
+geocoder.lookUp(point, 1, function(err, res) {
+ console.log(JSON.stringify(res, null, 2));
+});
+
+// In batch mode with many points
+var points = [
+ {latitude: 42.083333, longitude: 3.1},
+ {latitude: 48.466667, longitude: 9.133333}
+];
+geocoder.lookUp(points, 1, function(err, res) {
+ console.log(JSON.stringify(res, null, 2));
+});
var debug = require('debug')('local-reverse-geocoder');
var fs = require('fs');
-var path = require('path');
var parser = require('csv-parse');
var parse = parser.parse;
var kdTree = require('kdt');
-var fetch = (...args) =>
- import('node-fetch').then(({ default: fetch }) => fetch(...args));
var unzip = require('unzip-stream');
var async = require('async');
var readline = require('readline');
const { basename } = require('path');
+// mod.cjs
+const fetch = (...args) =>
+ import('node-fetch').then(({ default: fetch }) => fetch(...args));
// All data from http://download.geonames.org/export/dump/
var GEONAMES_URL = 'https://download.geonames.org/export/dump/';
@@ -169,7 +169,7 @@
Source: index.js
downloadMethodBoundToThis,
callback
) {
- const now = new Date().toISOString().substr(0, 10);
+ const now = new Date().toISOString().substring(0, 10);
// Use timestamped file OR bare file
const timestampedBasename = `${baseName}_${now}.txt`;
@@ -222,7 +222,7 @@
Source: index.js
.then((response) => {
if (!response.ok) {
throw new Error(
- `Error downloading GeoNames ${dataName} data (response ${response.status} for url ${geonamesUrl})`
+ `Error downloading GeoNames ${dataName} data (response ${response.status} for URL ${geonamesUrl})`
);
}
@@ -270,7 +270,7 @@
Source: index.js
.then((response) => {
if (!response.ok) {
throw new Error(
- `Error downloading GeoNames ${dataName} data (response ${response.status} for url ${geonamesUrl})`
+ `Error downloading GeoNames ${dataName} data (response ${response.status} for URL ${geonamesUrl})`
);
}
@@ -285,7 +285,7 @@
Source: index.js
.on('entry', (entry) => {
var entryPath = entry.path;
var entryType = entry.type; // 'Directory' or 'File'
- var entrySize = entry.size; // might be undefined in some archives
+ var entrySize = entry.size; // Might be undefined in some archives
if (entryType === 'File' && entryPath === fileNameInsideZip) {
debug(
`Unzipping GeoNames ${dataName} data - found ${entryType} ${entryPath}` +
@@ -311,13 +311,12 @@
Source: index.js
}
})
.on('finish', () => {
- // beware - this event is a finish of unzip, finish event of writeStream may and will happen later ...
+ // Beware - this event is a finish of unzip, finish event of writeStream may and will happen later...
if (foundFiles === 1) {
- // ... so if we found one file, we call callback in it's finish event above
+ // ...so if we found one file, we call callback in it's finish event above
debug(`Unzipped GeoNames ${dataName} data.`);
- // return callback(null, outputFilePath);
} else {
- // .. while if there is something unexpected, we fire callback here
+ // ...while if there is something unexpected, we fire callback here
debug(
`Error unzipping ${geonamesZipFilename}: Was expecting ${outputFileName}, found ${foundFiles} file(s).`
);
@@ -989,7 +988,7 @@