Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including country-iso with all npm packages installed. Try it out:

var countryIso = require("country-iso")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

country-iso v2.0.5

Get ISO 3166-1 alpha-3 country code for geographic coordinates.

country-iso

Travis CI Codecov npm npm version npm dependencies npm dev dependencies

🗺 Get ISO 3166-1 alpha-3 country code for geographic coordinates.

Click on the map for a live preview.

Install

$ npm install --save country-iso

Usage

You can query any (lat,lng) pair on the earth. It also works for territorial waters and disputed countries.

const countryIso = require('country-iso');

// Query a point in Italy.
countryIso.get(41.9028, 12.4964);
// => ['ITA']

// Query a disputed country.
countryIso.get(24, -14);
// => ['ESH', 'MAR']

// Query a point somewhere in Atlantic Ocean.
countryIso.get(40, -40);
// => []

The package internally uses @geo-maps/countries-maritime map with 10m resolution.

The accuracy of the map has been tested with 23785 cities.

API

get(lat, lng) ⇒ Array.<string>

Searches for every country which contains the point (lat, lng).

Returns: Array.<string> - Array of ISO 3166 alpha-3 country code for the geographic coordinates.

ParamTypeDescription
latnumberThe latitude of the point.
lngnumberThe 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.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free