tomayac / local-reverse-geocoder

Local reverse geocoder for Node.js based on GeoNames data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

False lookup when using countries array

miketerra opened this issue · comments

Hello, I have encountered an issue when loading individual countries.

The error occurs when more than one countries is defined in the countries array.
While it downloads all the country files correctly, only the last value of the array
is taken into consideration for the lookup.

To replicate:

let geocoder = require("local-reverse-geocoder");
geocoder.init(
  {
    load: {
      admin1: true,
      admin2: false,
      admin3And4: false,
      alternateNames: false,
    },
    // Comma-separated list of country codes. An empty array means all countries.
    countries: ["GR", "IT"],
  },
  async function () {
    let point = {
      latitude: 37.97519,
      longitude: 23.78488,
    };
    await geocoder.lookUp(point, function (err, georeport) {
      console.log(georeport);
    });
  }
);

Erroneous result:

  [
    {
      geoNameId: '6621108',
      name: 'Torre Montelungo',
      asciiName: 'Torre Montelungo',
      alternateNames: null,
      latitude: '39.81636',
      longitude: '18.38803',
      featureClass: 'S',
      featureCode: 'TOWR',
      countryCode: 'IT',
      cc2: null,
      admin1Code: '13',
      admin2Code: 'LE',
      admin3Code: '075028',
      admin4Code: null,
      population: '0',
      elevation: '68',
      dem: '68',
      timezone: 'Europe/Rome',
      modificationDate: '2012-08-30',
      distance: 509.836862114379
    }
  ]
]

Expected result:

[
  [
    {
      geoNameId: '8133877',
      name: 'Dimos Zografos',
      asciiName: 'Dimos Zografos',
      alternateNames: 'Zografos,Zografou,Ζωγράφος,Ζωγράφου',
      latitude: '37.97457',
      longitude: '23.79173',
      featureClass: 'A',
      featureCode: 'ADM3',
      countryCode: 'GR',
      cc2: null,
      admin1Code: 'ESYE31',
      admin2Code: '99',
      admin3Code: '9190',
      admin4Code: null,
      population: '71026',
      elevation: null,
      dem: '245',
      timezone: 'Europe/Athens',
      modificationDate: '2019-10-23',
      distance: 0.6043666635927379
    }
  ]
]

Changing the order countries: ["IT", "GR"] works correctly for Greece and not for Italy.

node -v
v16.14.0

Thanks for the report! Do you have time to work on a fix for this issue?

You are welcome!
Unfortunately, my schedule is full.

But to further update, when I remove the timestamps from the countries' s dump files and empty the array
countries: [],
everything works correctly.
To me it seems to be a problem with the countries array.

Hope it helps!

Fixed via #62.