Tool or PHP code to convert IP address into lat/ln

2020-05-24 16:38发布

I have thousands of IP addresses of visitors to my site, what tools can I use to convert these into lat/lng coordinates? I will then be able visualise the data on a map with filters for further demographics gathered.

4条回答
狗以群分
3楼-- · 2020-05-24 17:14

http://www.telize.com and http://www.iptolatlng.com both provide solutions in JSON

查看更多
趁早两清
4楼-- · 2020-05-24 17:23

For one of my sites I made use of maxmind's free geolite country database which can be downloaded here: http://www.maxmind.com/app/geolitecountry

They also provide a city level version which includes the long/lat: http://www.maxmind.com/app/geolitecity

but note that the accuracy on the free version is a lot lower than the paid version.

查看更多
小情绪 Triste *
5楼-- · 2020-05-24 17:31

I suggest using Google Analytics to your problem, but if you want to try yourself here is a starting point:

Take a look at this link http://www.geoplugin.net/php.gp, you get a full list of details about that ip address position, including latitude and longitude.

It is not that acurate but it works, and I use it. Here is a php script actually in use :

<?php
$ip_addr = $_SERVER['REMOTE_ADDR'];
$geoplugin = unserialize( file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ip_addr) );

if ( is_numeric($geoplugin['geoplugin_latitude']) && is_numeric($geoplugin['geoplugin_longitude']) ) {

$lat = $geoplugin['geoplugin_latitude'];
$long = $geoplugin['geoplugin_longitude'];
}
echo $ip_addr.';'.$lat.';'.$long;
?>

You can see it working at http://whateverhappens.org/ip-addr/

And that a look at the Geoplugin website examples.

查看更多
登录 后发表回答