Geo-location JS library
This library uses the service exposed by https://ip.nf and wraps its JSON result into a function.
Import the library into your project:
<script src="geolocateJS.js"></script>Call it when you need it:
geolocateJS.locate(function(locationData){
alert('You are from ' + locationData.ip.country);
});The object geolocateJS.locationObject will hold the location object after the call to the locate() function.
geolocateJS.locationObject.countrywill hold the textual versiongeolocateJS.locationObject.country_codewill hold the country code
Many thanks to the folks at https://www.whatwedo.ch/ for providing the geo-location service!