coordinate_to_country
v1.1.0
Published
Returns and ISO 3166-1 country code for any given latitude or longitude.
Downloads
6,645
Maintainers
Readme
#coordinate_to_country
This is a fork of country-iso with some bugfixes and additional features:
- Enclaves and exclaves are now handled properly: the dataset used by
country-iso
doesn't handle polygons with holes in them, resulting in weird outputs such as the entirety of Lesotho being shown as a part of South Africa. - ISO 3166 alpha-2 codes are now also optionally supported.
Both of these are accomplished thanks to a new dataset I generated, @osm_borders/maritime_10m. Just like its predecessor, it originates from high-quality OpenStreetMap data, but with fixes for the aforementioned issues. For more details, see the osm_borders Github page.
Installation and usage
This library can be installed using npm install coordinate_to_country
Querying a lat, lng pair is simple, with all queries returning an array of the countries which claim sovereignty over a given territory:
const lookup = require("coordinate_to_country");
lookup(53.218620, 6.567365); // => ["NLD"]
You can also request the alpha-2 version of the ISO-3166 by passing the optional isoA2 = true
parameter:
lookup(53.218620, 6.567365, true); // => ["NL"]
Disputed territories and coordinates not inside any country also work:
lookup(0, 0); // => []
lookup(45.739518, 18.953996); // => ["SRB", "HRV"]
Licence
This project is licensed under the MIT License.
This library was created by Emily Nagy (itisem) based on country-iso
by Simone Primarosa (simonepri).