在geolite2 .mmdb文件(JAVA)上按城市名称查询 [英] Query by city name on geolite2 .mmdb file (JAVA)
问题描述
我正在使用GeoLite2通过IP地址获取Java应用程序的位置.
I am using GeoLite2 to get Location by IP address for my java appliccation.
我想从GeoLite2-City.mmdb文件中按城市获取国家/地区.
I want to get country by city from GeoLite2-City.mmdb file.
这是我的读者:
DatabaseReader reader = new DatabaseReader.Builder(dbFileStream).withCache(new CHMCache()).build();
我正在通过IP地址获得CityResponse,如下所示:
I am getting CityResponse by IP address like below :
CityResponse cityResponse = reader.city(InetAddress.getByName("an IP address"));
但是我想按城市获取国家名称:
But I want to get Country name by city like this :
String countryName = reader.getCountryByCity("Paris");
有什么办法可以做到这一点?
Is there any way to do this ?
推荐答案
这是不可能的.该数据库旨在通过IP地址进行查找.如果您需要通过其他方式访问数据,我建议使用MaxMind提供的CSV文件.
This isn't possible. The database is designed to do lookups by IP address. I would suggest using the CSV files that MaxMind provides if you need to access the data in some other way.
此外,您可以尝试项目 geonames.org 和
Also, you can try project geonames.org and their java-api library
这篇关于在geolite2 .mmdb文件(JAVA)上按城市名称查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!