2015-08-17 36 views
0

是否有任何方式利用maxmind爲了通過用戶的IP獲取城市代碼?通過IP從GeoIP2城市數據庫獲取CityCode

在下面的例子中,我能夠獲得城市的名稱而不是cityCodes。據我所知,maxmind不支持城市代碼;

價爲的MaxMind支持:https://www.maxmind.com/en/geoip2-city

E.g;

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 
+0

您指的是哪個「城市代碼」?我不知道ISO城市代碼。有UN/LOCODE,IATA代碼,還有其他的。前者可能是使用來自GeoNames的數據可行的。 –

+0

對不起,以前。我的評論,這不是IATA代碼,我以後出去。我想有一個標準化如果有任何全球性的城市代碼標準。 NY爲Newyork,DUB爲Dublin等。 – shamaleyte

回答

0

據我所知,在UN/LOCODE是最匹配你所要求的。 MaxMind本身並未在其數據集中提供這些代碼,但它確實爲可用於在GeoNames數據集中查找城市的城市提供geoname_id。 GeoNames在他們的premium data set中提供UN/LOCODE。