country-iso
🗺 Get ISO 3166-1 alpha-3 country code for geographic coordinates.
Install
$ npm install --save country-iso
$ npm install --save world-countries-boundaries-100m
Countries bounds map file
In order to use this package you need to provide a valid GeoJSON
FeatureCollection object with the ISO_A3
property set for each country.
You can get one with customizable accuracy from world-countries-boundaries repo.
The accuracy of the maps has been tested with 23785 cities.
Usage
const countryCode = require('country-iso');
countryCode.use(require('world-countries-boundaries-1m')());
countryCode.get(42.50779, 1.52109);
API
use(geoJson)
Pre computes an R-Tree from a GeoJSON Object and uses the data future queries.
geoJson
Type: object
A valid GeoJSON FeatureCollection, each feature must have the ISO_A3
property.
get(lat, lng)
Searches for every country which contains the point (lat, lng).
lat
Type: number
Latitude of the point.
lng
Type: number
Longitude of the point.
Authors
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE file for details.