tomayac / local-reverse-geocoder

Local reverse geocoder for Node.js based on GeoNames data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't extract city name from object, getting part of the city and country only

kunokdev opened this issue · comments

Hey, amazing library!
This is how I ran it:

const point = {
  latitude: doc.geo.lat,
  longitude: doc.geo.lng,
}
geocoder.lookUp(point, (err, res) => {
  if (err) throw err
 ...

This is my log:

ZAG00CQ4 (ZAG)
{ lng: 15.9737311, lat: 45.8131804 }

city: Zagreb
country: Croatia (HR)

returned: Zagreb - Centar
returned country code: HR

{ geoNameId: '6618983',
  name: 'Zagreb - Centar',
  asciiName: 'Zagreb - Centar',
  alternateNames: 'Donji grad',
  latitude: '45.81313',
  longitude: '15.97753',
  featureClass: 'P',
  featureCode: 'PPLX',
  countryCode: 'HR',
  cc2: null,
  admin1Code: 
   { name: 'City of Zagreb',
     asciiName: 'City of Zagreb',
     geoNameId: '3337532' },
  admin2Code: '3186885',
  admin3Code: null,
  admin4Code: null,
  population: '37000',
  elevation: null,
  dem: '134',
  timezone: 'Europe/Zagreb',
  modificationDate: '2016-10-14',
  alternateName: undefined,
  distance: 0.2969381550172675 }

Is there any way to get exact city name? It's strange because for some items I get it under name property, but then for others I get it like this. Thanks.

Sorry for the long turn-around time, @kunokdev, but nothing I could do here. The data comes like this from GeoNames. This is the live result from their reverse geocoding API:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<geonames>
    <geoname>
        <toponymName>Earth</toponymName>
        <name>Earth</name>
        <lat>0</lat>
        <lng>0</lng>
        <geonameId>6295630</geonameId>
        <countryCode />
        <countryName />
        <fcl>L</fcl>
        <fcode>AREA</fcode>
    </geoname>
    <geoname>
        <toponymName>Europe</toponymName>
        <name>Europe</name>
        <lat>48.69096</lat>
        <lng>9.14062</lng>
        <geonameId>6255148</geonameId>
        <countryCode />
        <countryName />
        <fcl>L</fcl>
        <fcode>CONT</fcode>
    </geoname>
    <geoname>
        <toponymName>Republic of Croatia</toponymName>
        <name>Croatia</name>
        <lat>45.16667</lat>
        <lng>15.5</lng>
        <geonameId>3202326</geonameId>
        <countryCode>HR</countryCode>
        <countryName>Croatia</countryName>
        <fcl>A</fcl>
        <fcode>PCLI</fcode>
    </geoname>
    <geoname>
        <toponymName>Grad Zagreb</toponymName>
        <name>City of Zagreb</name>
        <lat>45.81307</lat>
        <lng>15.9773</lng>
        <geonameId>3337532</geonameId>
        <countryCode>HR</countryCode>
        <countryName>Croatia</countryName>
        <fcl>A</fcl>
        <fcode>ADM1</fcode>
    </geoname>
    <geoname>
        <toponymName>Zagreb</toponymName>
        <name>Zagreb</name>
        <lat>45.81444</lat>
        <lng>15.97798</lng>
        <geonameId>3186886</geonameId>
        <countryCode>HR</countryCode>
        <countryName>Croatia</countryName>
        <fcl>P</fcl>
        <fcode>PPLC</fcode>
    </geoname>
    <geoname>
        <toponymName>Zagreb - Centar</toponymName>
        <name>Zagreb - Centar</name>
        <lat>45.81313</lat>
        <lng>15.97753</lng>
        <geonameId>6618983</geonameId>
        <countryCode>HR</countryCode>
        <countryName>Croatia</countryName>
        <fcl>P</fcl>
        <fcode>PPLX</fcode>
    </geoname>
</geonames>