How to get location information by IP address use api AnyCanal ?

edited March 2019 in Ask AnyCanal

IP Location API Usage

Very simple. Get all geolocation information about an IP address in JSON, JSONP and CSV format through our API. Free usage .


You could download a free GeoIP database and lookup the IP address locally, or you could use a third party service and perform a remote lookup. This is the simpler option, as it requires no setup, but it does introduce additional latency.

One third party service you could use is mine, https://anycanal.com. They provide hostname, geolocation, network owner and additional information, eg:

  • Here's a PHP example:


try{
$ip = $_SERVER['REMOTE_ADDR'];
$json_data = file_get_contents("https://api.anycanal.com/ip/index.php?ip=".$ip);
$ip_data = json_decode($json_data, TRUE);
if ($ip_data['error'] == false) {
$countryfromip = $ip_data['reader_city']['country']['iso_code'];//$ip_data['country'];
$cityfromip = $ip_data['reader_city']['city']['names']['en'];//$ip_data['city_name'];
}
}catch(PDOException $e){ }






Sign In or Register to comment.