Helper class to read GeoNames data files with 0 dependencies.
import {GeoNames} from 'geonames';
const geoNames = new GeoNames('path/to/geonames.txt');
Generator function to get list of places found in the data file without loading all into memory at once.
for await (let place: Place of geoNames) {
console.log(place.name);
}
Finds the place nearest to the location provided, without loading all places into memory.
let nearest = geoNames.nearest({latitude: 53.33, longitude: -6.24});
console.log(`${nearest.name}, ${nearest.countryCode}`) // Dublin, IE
class Place {
id: number;
name: string;
asciiName: string;
alternativeNames: string[];
latitude: number;
longitude: number;
featureClass: string;
featureCode: string;
countryCode: string;
alternativeCountryCode: string;
adminCode1: string;
adminCode2: string;
adminCode3: string;
adminCode4: string;
population: number;
elevation: number;
digitalElevationModel: number;
timezone: string;
modificationDate: Date;
// Distance of place provided location
distance(to: {latitude: number, longitude: number}): number;
}