How to get the latitude and longitude value from an IP address using PHP?

I want to get the geographic coordinates IP addresses using the IPinfo API. I am using PHP.

-supportbot

You can use IPinfo’s PHP Client Library to get an IP address’ approximate geographic coordinates.

Install the client library with Composer:

php composer.phar require ipinfo/ipinfo

Then you are good to go. Feel free to use the following boilerplate code.

require_once __DIR__ . '/vendor/autoload.php';

use ipinfo\ipinfo\IPinfo;

$access_token = '123456789abc';
$client = new IPinfo($access_token);
$ip_address = '216.239.36.21';
$details = $client->getDetails($ip_address);

$details->loc; // 34.0293,-118.3570
$details->latitude; // 34.0293
$details->longitude; // -118.3570