tomayac / local-reverse-geocoder

Local reverse geocoder for Node.js based on GeoNames data
Apache License 2.0
190 stars 58 forks source link

False lookup when using countries array #46

Closed miketerra closed 1 year ago

miketerra commented 2 years ago

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

tomayac commented 2 years ago

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

miketerra commented 2 years ago

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!

tomayac commented 1 year ago

Fixed via #62.