看看http://www.geoplugin.com/webservices/php
echo var_export(unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR'])));
输出
array ( 'geoplugin_request' => '50.143.52.48', 'geoplugin_status' => 200, 'geoplugin_credit' => '一些返回的数据包括 MaxMind 创建的 GeoLite 数据,可从
http://www.maxmind.com获得。 ', 'geoplugin_city' => 'Pompano Beach',
'geoplugin_region' => 'FL', 'geoplugin_areaCode' => '954',
'geoplugin_dmaCode' => '528', 'geoplugin_countryCode' => 'US',
'geoplugin_countryName ' => '美国',
'geoplugin_continentCode' => 'NA', 'geoplugin_latitude' => '26.2442', 'geoplugin_longitude' => '-80.205902',
'geoplugin_regionCode' => 'FL', 'geoplugin_regionName' => '佛罗里达', 'geoplugin_currencyCode' => 'USD', 'geoplugin_currencySymbol' => '$', 'geoplugin_currencySymbol_UTF8' => '$',
'geoplugin_currencyConverter' => '1', )
PHP 类
<?php
require_once('geoplugin.class.php');
$geoplugin = new geoPlugin();
// If we wanted to change the base currency, we would uncomment the following line
// $geoplugin->currency = 'EUR';
$geoplugin->locate();
echo "Geolocation results for {$geoplugin->ip}: <br />\n".
"City: {$geoplugin->city} <br />\n".
"Region: {$geoplugin->region} <br />\n".
"Area Code: {$geoplugin->areaCode} <br />\n".
"DMA Code: {$geoplugin->dmaCode} <br />\n".
"Country Name: {$geoplugin->countryName} <br />\n".
"Country Code: {$geoplugin->countryCode} <br />\n".
"Longitude: {$geoplugin->longitude} <br />\n".
"Latitude: {$geoplugin->latitude} <br />\n".
"Currency Code: {$geoplugin->currencyCode} <br />\n".
"Currency Symbol: {$geoplugin->currencySymbol} <br />\n".
"Exchange Rate: {$geoplugin->currencyConverter} <br />\n";
if ( $geoplugin->currency != $geoplugin->currencyCode ) {
//our visitor is not using the same currency as the base currency
echo "<p>At todays rate, US$100 will cost you " . $geoplugin->convert(100) ." </p>\n";
}
/* find places nearby */
$nearby = $geoplugin->nearby();
if ( isset($nearby[0]['geoplugin_place']) ) {
echo "<pre><p>Some places you may wish to visit near " . $geoplugin->city . ": </p>\n";
foreach ( $nearby as $key => $array ) {
echo ($key + 1) .":<br />";
echo "\t Place: " . $array['geoplugin_place'] . "<br />";
echo "\t Country Code: " . $array['geoplugin_countryCode'] . "<br />";
echo "\t Region: " . $array['geoplugin_region'] . "<br />";
echo "\t County: " . $array['geoplugin_county'] . "<br />";
echo "\t Latitude: " . $array['geoplugin_latitude'] . "<br />";
echo "\t Longitude: " . $array['geoplugin_longitude'] . "<br />";
echo "\t Distance (miles): " . $array['geoplugin_distanceMiles'] . "<br />";
echo "\t Distance (km): " . $array['geoplugin_distanceKilometers'] . "<br />";
}
echo "</pre>\n";
}
?>
这将输出:
Geolocation results for 50.143.52.48:
City: Pompano Beach
Region: FL
Area Code: 954
DMA Code: 528
Country Name: United States
Country Code: US
Longitude: -80.205902
Latitude: 26.2442
Currency Code: USD
Currency Symbol: $
Exchange Rate: 1
Some places you may wish to visit near Pompano Beach:
1:
Place: Whispering Pines Addition Mobile Home Park
Country Code: US
Region: Florida
County:
Latitude: 26.2711000
Longitude: -80.1442900
Distance (miles): 4.25
Distance (km): 6.83
2:
Place: Coral Springs
Country Code: US
Region: Florida
County:
Latitude: 26.2711900
Longitude: -80.2706000
Distance (miles): 4.42
Distance (km): 7.12
3:
Place: Pompano Beach
Country Code: US
Region: Florida
County:
Latitude: 26.2378600
Longitude: -80.1247700
Distance (miles): 5.05
Distance (km): 8.12
4:
Place: Rock Island
Country Code: US
Region: Florida
County:
Latitude: 26.1550900
Longitude: -80.1769900
Distance (miles): 6.41
Distance (km): 10.32
5:
Place: Lighthouse Point
Country Code: US
Region: Florida
County:
Latitude: 26.2756400
Longitude: -80.0872700
Distance (miles): 7.66
Distance (km): 12.34