Retrieve instant information for any country with Laravel or Node.js
If you want to retrieve instant, accurate information for any country in the world, you can use countrylayer. The service is free to use!
What is countrylayer?
countrylayer is a service that can help us to get instant access to accurate country data for various geo-points in the world.
Features
The service has a rich set of capabilities.
Accurate Country API
Accurate country database based on official information from each country.
Forms Autocomplete
Customize user experience by identifying accurately users’ country, city, language, and more.
Bulk API Endpoint
You can integrate our countrylayer API into any of your applications written in any programming language.
Free to use
Get 100 searches a month FREE
Documentation
You can read the official documentation on the countrylayer website.
How to use
Register to get a free API key
You need to go to positionstack and register to get a free API key.
Using Raw PHP
You can use raw PHP to identify user IP. Here is the sample code:
$curl = curl.init();
curl.setopt_array($curl, array(
CURLOPT_URL=>
‘https://api.countrylayer.com/v2/all
? access_key = ((YOUR_ACCESS_KEY))’,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => ’’,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => ‘GET’,
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Using Node.js or Javascript
var settings = {
“url”: “https://api.countrylayer.com/v2/all
? access_key = ((YOUR_ACCESS_KEY))”,
“method”: “GET”,
“timeout”: 0,
};
$.ajax(settings).done(function (response) {
console.log (response);
});
If this post was helpful, please share this post with your friends and don't forget to follow our Facebook and Twitter pages!