The old freegeoip API is now deprecated and will be discontinued on July 1st, 2018.
The new API is from https://ipstack.com. You have to create the account in ipstack.Then you can use the access key in the API url.
$url = "http://api.ipstack.com/122.167.180.20?access_key=ACCESS_KEY&format=1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$response = json_decode($response);
$city = $response->city; //You can get all the details like longitude,latitude from the $response .
For more information check here :/ https://github.com/apilayer/freegeoip