Class LocationUtils

java.lang.Object
com.iizix.location.LocationUtils

public class LocationUtils extends Object
Class used to provide inaccurate geolocation from e.g. and IP address. This class makes use of requests of an inaccurate geolocation from an IP address by means of a web service. This web service mail take a long time and... and... you guessed it!
Author:
Christopher Mindus
  • Method Details

    • getGeoLocation

      public static boolean getGeoLocation(InetAddress ipAddress, BiFunction<GeoLocation,Exception,Void> callback)
      Gets the geo position and location information from an IP address if possible.

      If both the GeoPosition instance and the GeoLocation instance is null the call failed.

      Failures are always logger in the server as warnings.

      Parameters:
      ipAddress - The IP address try to look-up the location for.
      callback - The callback with the location. The callback takes two parameters: GeoLocation in case of success, null in case of error, and Exception in case of error. The function should return a null value,
      Returns:
      true if the service will be provided or not (i.e. not provided when the server is starting or stopping).
    • getGeoLocation

      public static boolean getGeoLocation(int logLevel, InetAddress ipAddress, BiFunction<GeoLocation,Exception,Void> callback)
      Gets the geo position and location information from an IP address if possible.

      If both the GeoPosition instance and the GeoLocation instance is null the call failed.

      Failures are always logger in the server.

      Parameters:
      logLevel - Level of log gravity (Log.SEVERE to LOG.FINEST).
      ipAddress - The IP address try to look-up the location for.
      callback - The callback with the location. The callback takes two parameters: GeoLocation in case of success, null in case of error, and Exception in case of error. The function should return a null value,
      Returns:
      true if the service will be provided or not (i.e. not provided when the server is starting or stopping).
    • getGeoLocation

      public static GeoLocation getGeoLocation(InetAddress ipAddress) throws IOException, JSONException
      Gets the geo position and location information from an IP address if possible.

      This call is synchronous.

      Failures are always logger in the server as warnings.

      Parameters:
      ipAddress - The IP address try to look-up the location for.
      Returns:
      The geolocation instance with longitude and latitude set (timestamp is set to "now" and accuracy to zero).
      Throws:
      IOException - For I/O errors.
      JSONException - For JSON errors.
    • getGeoLocation

      public static GeoLocation getGeoLocation(int logLevel, InetAddress ipAddress) throws IOException, JSONException
      Gets the geo position and location information from an IP address if possible.

      This call is synchronous.

      Failures are always logger in the server.

      Parameters:
      logLevel - Level of log gravity (Log.SEVERE to LOG.FINEST).
      ipAddress - The IP address try to look-up the location for.
      Returns:
      The geolocation instance with longitude and latitude set (timestamp is set to "now" and accuracy to zero).
      Throws:
      IOException - For I/O errors.
      JSONException - For JSON errors.
    • main

      public static void main(String[] args)
      Test code.