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

1.1k views Asked by At

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

There are 1 answers

0
Dmitriy On

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