Returns and ISO 3166-1 country code for any given latitude or longitude.
npm install coordinate_to_country#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.
npm install coordinate_to_country
javascript
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:
`javascript
lookup(53.218620, 6.567365, true); // => ["NL"]
`
Disputed territories and coordinates not inside any country also work:
`javascript
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).