Git Product home page Git Product logo

find-nearest-cities's Introduction

find-nearest-cities

Searches the nearest cities, using geokdbush. Data taken from cities1000 at geonames.org

build status npm version ISC-licensed

Installing

npm install find-nearest-cities

Warning: Package Size

This package includes the full 56MB JSON for all the cities, which are all loaded into memory

Usage

const nearestStations = require('find-nearest-cities')

const latitude = 52.509647;
const longitude = 13.375944;

const cities = nearestCities(latitude, longitude);

// [{
//    id: '2822224',
//    name: 'Tiergarten',
//    asciiname: 'Tiergarten Bezirk',
//    alternativeNames: ['Berlin-Tiergarten',
//       'Tirgarten',
//       'Tyrgartehn',
//       'di er jia teng',
//       'Тиргартен',
//       'Тыргартэн',
//       'טירגארטן',
//       '蒂尔加滕'
//    ],
//    lat: 52.51667,
//    lon: 13.36667,
//    featureClass: 'P',
//    featureCode: 'PPLX',
//    country: 'DE',
//    altCountry: '',
//    adminCode: '16',
//    countrySubdivision: '00',
//    municipality: '11000',
//    municipalitySubdivision: '11000000',
//    population: 12328,
//    dem: '36',
//    tz: 'Europe/Berlin',
//    lastModified: '2012-06-09',
//    distance: 1281
// }]

API

nearestCities(longitude, latitude[, maxDistance, maxResults])

Returns an array of the closest points from a given location in order of increasing distance.

  • longitude: query point longitude.
  • latitude: query point latitude.
  • maxDistance: (optional) maximum distance in meters to search within (Infinity by default).
  • maxResults: (optional) maximum number of points to return (5 by default).

Contributing

If you have a question, found a bug or want to propose a feature, have a look at the issues page.

Data License

The Dataset is published under Creative Commons Attribution 4.0 International by geonames.org.

find-nearest-cities's People

Contributors

steffenmllr avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

find-nearest-cities's Issues

Not fetching the correct cities

I live in BC Canada, my lat/long (49.119626, -122.691090) and the result I'm getting are cities from Winnipeg, 2.287km away from me. Something needs to be checked in your code.


   let listOfCities=[]
    const latitude = 49.119626;
    const longitude = -122.691090;
    listOfCities = nearestCities(latitude, longitude,[,5]);

[ { id: '5884260', name: 'Altona', asciiname: 'Altona', alternativeNames: [ 'Altona', 'altwna manytwba', 'Алтона', 'التونا، مانیتوبا', 'الٹونا، مینی ٹوبا' ], lat: 49.10469, lon: -97.55961, featureClass: 'P', featureCode: 'PPL', country: 'CA', altCountry: '', adminCode: '03', countrySubdivision: '', municipality: '', municipalitySubdivision: '', population: 3613, dem: '246', tz: 'America/Winnipeg', lastModified: '2008-04-11', distance: 2794497 }, { id: '5058568', name: 'Cavalier', asciiname: 'Cavalier', alternativeNames: [ 'Kavalir', 'ka wa lai er', 'kafalyr', 'kwlyr dakwtay shmaly', 'Кавалир', 'كافالير', 'کولیر، داکوتای شمالی', 'کیویلیئر، شمالی ڈکوٹا', '卡瓦莱尔' ], lat: 48.79388, lon: -97.62231, featureClass: 'P', featureCode: 'PPLA2', country: 'US', altCountry: '', adminCode: 'ND', countrySubdivision: '067', municipality: '12940', municipalitySubdivision: '', population: 1244, elevation: 270, dem: '269', tz: 'America/Chicago', lastModified: '2017-05-23', distance: 2787543 }, { id: '6183204', name: 'Winkler', asciiname: 'Winkler', alternativeNames: [ 'Uinkler', 'Vinkler', 'wnklr', 'Винклер', 'Вінклер', 'Уинклер', 'ونکلر', 'ونکلر، مینی ٹوبا' ], lat: 49.1817, lon: -97.94104, featureClass: 'P', featureCode: 'PPL', country: 'CA', altCountry: '', adminCode: '03', countrySubdivision: '', municipality: '', municipalitySubdivision: '', population: 8270, dem: '271', tz: 'America/Winnipeg', lastModified: '2008-04-11', distance: 2752085 }, { id: '5917275', name: 'Carman', asciiname: 'Carman', alternativeNames: [ 'Karman', 'Карман' ], lat: 49.4992, lon: -98.00156, featureClass: 'P', featureCode: 'PPL', country: 'CA', altCountry: '', adminCode: '03', countrySubdivision: '', municipality: '', municipalitySubdivision: '', population: 2948, dem: '264', tz: 'America/Winnipeg', lastModified: '2008-04-11', distance: 2745380 }, { id: '6078447', name: 'Morden', asciiname: 'Morden', alternativeNames: [ 'Morden', 'Морден', 'مورڈن، مینی ٹوبا' ], lat: 49.1919, lon: -98.10136, featureClass: 'P', featureCode: 'PPL', country: 'CA', altCountry: '', adminCode: '03', countrySubdivision: '', municipality: '', municipalitySubdivision: '', population: 6395, dem: '306', tz: 'America/Winnipeg', lastModified: '2008-04-11', distance: 2734258 } ]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.