Query by city name on geolite2 .mmdb file (JAVA)

狂风中的少年 提交于 2021-01-27 17:02:01

问题


I am using GeoLite2 to get Location by IP address for my java appliccation.

I want to get country by city from GeoLite2-City.mmdb file.

This is my reader :

DatabaseReader reader = new DatabaseReader.Builder(dbFileStream).withCache(new CHMCache()).build();

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 ?


回答1:


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.

Also, you can try project geonames.org and their java-api library



来源:https://stackoverflow.com/questions/51740363/query-by-city-name-on-geolite2-mmdb-file-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!