Gathering detailed insights and metrics for @triplestepab/all-the-cities
Gathering detailed insights and metrics for @triplestepab/all-the-cities
Gathering detailed insights and metrics for @triplestepab/all-the-cities
Gathering detailed insights and metrics for @triplestepab/all-the-cities
npm install @triplestepab/all-the-cities
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
This package contains all the cities with population, gps coordinates and (to some degree) alternative spellings for the following countries:
AD, AE, AF, AG, AI, AL, AM, AN, AO, AQ, AR, AS, AT, AU, AW, AX, AZ, BA, BB, BD, BE, BF, BG, BH, BI, BJ, BL, BM, BN, BO, BQ, BR, BS, BT, BV, BW, BY, BZ, CA, CC, CD, CF, CG, CH, CI, CK, CL, CM, CN, CO, CR, CS, CU, CV, CW, CX, CY, CZ, DE, DJ, DK, DM, DO, DZ, EC, EE, EG, EH, ER, ES, ET, FI, FJ, FK, FM, FO, FR, GA, GB, GD, GE, GF, GG, GH, GI, GL, GM, GN, GP, GQ, GR, GS, GT, GU, GW, GY, HK, HM, HN, HR, HT, HU, ID, IE, IL, IM, IN, IO, IQ, IR, IS, IT, JE, JM, JO, JP, KE, KG, KH, KI, KM, KN, KP, KR, KW, KY, KZ, LA, LB, LC, LI, LK, LR, LS, LT, LU, LV, LY, MA, MC, MD, ME, MF, MG, MH, MK, ML, MM, MN, MO, MP, MQ, MR, MS, MT, MU, MV, MW, MX, MY, MZ, NA, NC, NE, NF, NG, NI, NL, NO, NP, NR, NU, NZ, OM, PA, PE, PF, PG, PH, PK, PL, PM, PN, PR, PS, PT, PW, PY, QA, RE, RO, RS, RU, RW, SA, SB, SC, SD, SE, SG, SH, SI, SJ, SK, SL, SM, SN, SO, SR, SS, ST, SV, SX, SY, SZ, TC, TD, TF, TG, TH, TJ, TK, TL, TM, TN, TO, TR, TT, TV, TW, TZ, UA, UG, UM, US, UY, UZ, VA, VC, VE, VG, VI, VN, VU, WF, WS, XK, YE, YT, YU, ZA, ZM, ZW,
It also contains code to accurately calcaulate the distance between two given gps coordinates.
The data comes from geonames.org. For a list of countries, see http://download.geonames.org/export/dump/.
1 import * as allTheCities from "@triplestepab/all-the-cities"; 2 3 // **************************************************** 4 // Find two cities and calculate distance between them 5 // **************************************************** 6 7 const city1 = allTheCities.findCity("SE", "Eslöv"); 8 const city2 = allTheCities.findCity("SE", "Stockholm"); 9 10 if (city1.length > 0 && city2.length > 0) { 11 console.log("City 1 found:"); 12 console.log(city1[0]); 13 console.log("City 2 found:"); 14 console.log(city2[0]); 15 console.log("Distance between them:"); 16 console.log(allTheCities.distanceBetweenCities(city1[0], city2[0])); 17 } 18 19 // **************************************************** 20 // Find the 10 nearest cities on these coordinates 21 // **************************************************** 22 23 const lat = 55.839435 as Latitude; 24 const long = 13.303121 as Longitude; 25 26 console.log(`Find the 10 nearest cities on these coordinates. Lat: ${lat}, Long: ${long}`); 27 console.log(allTheCities.findNearestCities("SE", lat, long, 10)); 28 29 // **************************************************** 30 // Find the cities within 10km on these coordinates 31 // **************************************************** 32 33 console.log(`Find the cities within 10km on these coordinates. Lat: ${lat}, Long: ${long}`); 34 console.log(allTheCities.findNearBy("SE", lat, long, 10000)); 35 36 // **************************************************** 37 // Find all cities with a population over 100000 and sort them by population 38 // **************************************************** 39 40 const allCities = allTheCities.getData("SE"); 41 console.log(allCities.filter(c => c.population > 100000).sort((c1, c2) => c2.population - c1.population).map(c => c.name)); 42
The Longitude
and Latitude
datatypes are branded. To "cast" numbers to the right type, do this:
1 const lat = 55.839435 as Latitude; 2 const long = 13.303121 as Longitude;
The data was sorted using:
1 const collator = new Intl.Collator(countryCode); 2 countryData.sort((a, b) => collator.compare(a.name, b.name));
Upon searching a country, the file for that requested country is loaded into memory and kept there. Upon searching all countries, there's a good chance the memory footprint is huge (The countryData
folder is some 500Mb on disk).
Thanks to Chris Veness at Movable-Type for some serious math and code (licensed under MIT). Take a look at the excellent work at https://www.movable-type.co.uk/scripts/latlong.html.
The original data was downloaded from http://download.geonames.org/export/dump/ (licensed under a Creative Commons Attribution 4.0 License).
No vulnerabilities found.
No security vulnerabilities found.