如何使用maxmind从IP地址获取经纬度?
How to get latitude and longitude from IP address using maxmind?
我使用 geoip php 扩展有一段时间了。
此扩展程序不像以前那样为我提供纬度和经度。
查看 maxmind 网站,我可以阅读:
Note: After careful consideration, taking into account customer
feedback, we have decided against removing latitude and longitude
coordinates from the GeoLite2 databases. We are in the process of
reviewing coordinates used in all of our GeoLite2 and GeoIP databases
to ensure there is no risk of misuse.
是否有其他方法(或免费替代方法)从 IP 地址获取纬度和经度?
您可以使用 http://ip-api.com/ 提供的免费服务。
向 http://ip-api.com/json/111.222.333.444/ 发出 GET 请求(在要查找的末尾附加您自己的 IP)
结果将如下所示:
{
"status": "success",
"country": "COUNTRY",
"countryCode": "COUNTRY CODE",
"region": "REGION CODE",
"regionName": "REGION NAME",
"city": "CITY",
"zip": "ZIP CODE",
"lat": LATITUDE,
"lon": LONGITUDE,
"timezone": "TIME ZONE",
"isp": "ISP NAME",
"org": "ORGANIZATION NAME",
"as": "AS NUMBER / NAME",
"query": "IP ADDRESS USED FOR QUERY"
}
我相信这就是您要问的那种数据; LAT/LON 是一个标准的 return 和这个 API。注意不要每分钟执行超过 150 个请求,否则他们将禁止您的主机发出进一步的请求。
您可以使用免费的 IP2Location LITE DB5 和 PHP 库。
PHP 图书馆
https://www.ip2location.com/developers/php
IP2Location LITE DB5
https://lite.ip2location.com/database/ip-country-region-city-latitude-longitude
<?php
require_once 'IP2Location.php';
/*
Default file I/O lookup
*/
$db = new \IP2Location\Database('./databases/IP-COUNTRY-SAMPLE.BIN', \IP2Location\Database::FILE_IO);
$records = $db->lookup('8.8.8.8', \IP2Location\Database::ALL);
echo '<pre>';
echo 'IP Number : ' . $records['ipNumber'] . "\n";
echo 'IP Version : ' . $records['ipVersion'] . "\n";
echo 'IP Address : ' . $records['ipAddress'] . "\n";
echo 'Country Code : ' . $records['countryCode'] . "\n";
echo 'Country Name : ' . $records['countryName'] . "\n";
echo 'Region Name : ' . $records['regionName'] . "\n";
echo 'City Name : ' . $records['cityName'] . "\n";
echo 'Latitude : ' . $records['latitude'] . "\n";
echo 'Longitude : ' . $records['longitude'] . "\n";
echo 'Area Code : ' . $records['areaCode'] . "\n";
echo 'IDD Code : ' . $records['iddCode'] . "\n";
echo 'Weather Station Code : ' . $records['weatherStationCode'] . "\n";
echo 'Weather Station Name : ' . $records['weatherStationName'] . "\n";
echo 'MCC : ' . $records['mcc'] . "\n";
echo 'MNC : ' . $records['mnc'] . "\n";
echo 'Mobile Carrier : ' . $records['mobileCarrierName'] . "\n";
echo 'Usage Type : ' . $records['usageType'] . "\n";
echo 'Elevation : ' . $records['elevation'] . "\n";
echo 'Net Speed : ' . $records['netSpeed'] . "\n";
echo 'Time Zone : ' . $records['timeZone'] . "\n";
echo 'ZIP Code : ' . $records['zipCode'] . "\n";
echo 'Domain Name : ' . $records['domainName'] . "\n";
echo 'ISP Name : ' . $records['isp'] . "\n";
echo '</pre>';
?>
他们最近改变了删除 Lat/Lon 数据的想法,因此它将在现有的 GeoLite2 中再次可用。他们只是在重新部署 Lat/Lon 数据之前验证他们的数据。
Note: After careful consideration, taking into account customer
feedback, we have decided against removing latitude and longitude
coordinates from the GeoLite2 databases.* We are in the process of
reviewing coordinates used in all of our GeoLite2 and GeoIP databases
to ensure there is no risk of misuse.
参考:https://dev.maxmind.com/geoip/geoip2/geolite2/
[编辑] 因此,要根据上述内容实际重新发布,您将能够像以前一样继续,而无需实施新的 library/service
我使用 geoip php 扩展有一段时间了。 此扩展程序不像以前那样为我提供纬度和经度。
查看 maxmind 网站,我可以阅读:
Note: After careful consideration, taking into account customer feedback, we have decided against removing latitude and longitude coordinates from the GeoLite2 databases. We are in the process of reviewing coordinates used in all of our GeoLite2 and GeoIP databases to ensure there is no risk of misuse.
是否有其他方法(或免费替代方法)从 IP 地址获取纬度和经度?
您可以使用 http://ip-api.com/ 提供的免费服务。
向 http://ip-api.com/json/111.222.333.444/ 发出 GET 请求(在要查找的末尾附加您自己的 IP)
结果将如下所示:
{
"status": "success",
"country": "COUNTRY",
"countryCode": "COUNTRY CODE",
"region": "REGION CODE",
"regionName": "REGION NAME",
"city": "CITY",
"zip": "ZIP CODE",
"lat": LATITUDE,
"lon": LONGITUDE,
"timezone": "TIME ZONE",
"isp": "ISP NAME",
"org": "ORGANIZATION NAME",
"as": "AS NUMBER / NAME",
"query": "IP ADDRESS USED FOR QUERY"
}
我相信这就是您要问的那种数据; LAT/LON 是一个标准的 return 和这个 API。注意不要每分钟执行超过 150 个请求,否则他们将禁止您的主机发出进一步的请求。
您可以使用免费的 IP2Location LITE DB5 和 PHP 库。
PHP 图书馆 https://www.ip2location.com/developers/php
IP2Location LITE DB5 https://lite.ip2location.com/database/ip-country-region-city-latitude-longitude
<?php
require_once 'IP2Location.php';
/*
Default file I/O lookup
*/
$db = new \IP2Location\Database('./databases/IP-COUNTRY-SAMPLE.BIN', \IP2Location\Database::FILE_IO);
$records = $db->lookup('8.8.8.8', \IP2Location\Database::ALL);
echo '<pre>';
echo 'IP Number : ' . $records['ipNumber'] . "\n";
echo 'IP Version : ' . $records['ipVersion'] . "\n";
echo 'IP Address : ' . $records['ipAddress'] . "\n";
echo 'Country Code : ' . $records['countryCode'] . "\n";
echo 'Country Name : ' . $records['countryName'] . "\n";
echo 'Region Name : ' . $records['regionName'] . "\n";
echo 'City Name : ' . $records['cityName'] . "\n";
echo 'Latitude : ' . $records['latitude'] . "\n";
echo 'Longitude : ' . $records['longitude'] . "\n";
echo 'Area Code : ' . $records['areaCode'] . "\n";
echo 'IDD Code : ' . $records['iddCode'] . "\n";
echo 'Weather Station Code : ' . $records['weatherStationCode'] . "\n";
echo 'Weather Station Name : ' . $records['weatherStationName'] . "\n";
echo 'MCC : ' . $records['mcc'] . "\n";
echo 'MNC : ' . $records['mnc'] . "\n";
echo 'Mobile Carrier : ' . $records['mobileCarrierName'] . "\n";
echo 'Usage Type : ' . $records['usageType'] . "\n";
echo 'Elevation : ' . $records['elevation'] . "\n";
echo 'Net Speed : ' . $records['netSpeed'] . "\n";
echo 'Time Zone : ' . $records['timeZone'] . "\n";
echo 'ZIP Code : ' . $records['zipCode'] . "\n";
echo 'Domain Name : ' . $records['domainName'] . "\n";
echo 'ISP Name : ' . $records['isp'] . "\n";
echo '</pre>';
?>
他们最近改变了删除 Lat/Lon 数据的想法,因此它将在现有的 GeoLite2 中再次可用。他们只是在重新部署 Lat/Lon 数据之前验证他们的数据。
Note: After careful consideration, taking into account customer feedback, we have decided against removing latitude and longitude coordinates from the GeoLite2 databases.* We are in the process of reviewing coordinates used in all of our GeoLite2 and GeoIP databases to ensure there is no risk of misuse.
参考:https://dev.maxmind.com/geoip/geoip2/geolite2/
[编辑] 因此,要根据上述内容实际重新发布,您将能够像以前一样继续,而无需实施新的 library/service