Search in sources :

Example 1 with GeoIP

use of com.baeldung.spring.form.GeoIP in project tutorials by eugenp.

the class RawDBDemoGeoIPLocationService method getLocation.

public GeoIP getLocation(String ip) throws IOException, GeoIp2Exception {
    InetAddress ipAddress = InetAddress.getByName(ip);
    CityResponse response = dbReader.city(ipAddress);
    String cityName = response.getCity().getName();
    String latitude = response.getLocation().getLatitude().toString();
    String longitude = response.getLocation().getLongitude().toString();
    return new GeoIP(ip, cityName, latitude, longitude);
}
Also used : CityResponse(com.maxmind.geoip2.model.CityResponse) GeoIP(com.baeldung.spring.form.GeoIP) InetAddress(java.net.InetAddress)

Aggregations

GeoIP (com.baeldung.spring.form.GeoIP)1 CityResponse (com.maxmind.geoip2.model.CityResponse)1 InetAddress (java.net.InetAddress)1