このデータベースは次のとおりです。In our recent tests, the GeoIP databases tested at 99.8% accurate on a country level, 90% accurate on a state level in the US, and 83% accurate for cities in the US within a 40 kilometer radius.
私は次のようなものを調べます: PEAR GeoLite ライブラリ
PHP でこのライブラリを使用する簡単なスニペット:
$geoip = Net_GeoIP::getInstance(dirname(__FILE__) . '/data/GeoLiteCity.dat');
$ipaddress = '72.30.2.43'; // Yahoo!
$location = $geoip->lookupLocation($ipaddress);
var_dump($location);
次のような出力が表示されます。
object(Net_GeoIP_Location)[2]
protected 'aData' =>
array
'countryCode' => string 'US' (length=2)
'countryCode3' => string 'USA' (length=3)
'countryName' => string 'United States' (length=13)
'region' => string 'CA' (length=2)
'city' => string 'Sunnyvale' (length=9)
'postalCode' => string '94089' (length=5)
'latitude' => float 37.4249
'longitude' => float -122.0074
'areaCode' => int 408
'dmaCode' => float 807