【问题标题】:Get CityCode By IP from GeoIP2 City Database从 GeoIP2 城市数据库中按 IP 获取 CityCode
【发布时间】:2015-11-09 19:09:48
【问题描述】:

有没有什么方法可以利用 maxmind 来通过用户的 IP 获取城市代码?

在下面的示例中,我能够获取城市的名称,但不能获取 cityCodes。据我所知 maxmind 不支持城市代码;

maxmind 支持参考:https://www.maxmind.com/en/geoip2-city

例如;

private static DatabaseReader reader = null;
InetAddress inetAddress = InetAddress.getByName(ipAddress);         
CityResponse response = reader.city(inetAddress);
String cityName = response.getCity().getName(); //Istanbul
String cityCode = response.getCity().???code???; // The desired output : IST

【问题讨论】:

  • 您具体指的是哪个“城市代码”?我不知道 ISO 城市代码。有 UN/LOCODE、IATA 代码,也许还有其他代码。前者可以使用 GeoNames 中的数据来实现。
  • 对不起上一个。我的评论,这不是我所追求的 IATA 代码。如果有任何城市代码的全球标准,我希望有一个标准化。 NY 代表纽约,DUB 代表都柏林等。

标签: maxmind


【解决方案1】:

据我所知,UN/LOCODE 与您的要求最接近。 MaxMind 本身并没有在其数据集中提供这些代码,但它确实为城市提供了一个geoname_id,可用于在GeoNames 数据集中查找城市。 GeoNames 在其premium data set 中提供 UN/LOCODE。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多