Skip to content

akofman/getCountry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

getCountry

Simple function that returns the ISO 3166-1 alpha-3 country code of the country where you are geolocated.

The implementation wraps the HTML5 navigator.geolocation.getCurrentPosition function in a promise and uses the which-country lib in order to retrieve a country from its coords.

Usage

getCountry().then(function(country){
  console.log(country);
});

You can handle errors with a callback param :

getCountry({errorHandler: function(error){
  console.log(error);
}}).then(function(country){
  console.log(country);
});

Position options are also accepted :

getCountry({errorHandler: function(error){
  console.log(error);
}, options: {
  maximumAge: 0
}}).then(function(country){
  console.log(country);
});

License

MIT © Alexis Kofman

About

Retrieve in which country you are from the HTML5 geolocation API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published