Class LocationUtils


  • public class LocationUtils
    extends java.lang.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 Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static GeoLocation getGeoLocation​(int logLevel, java.net.InetAddress ipAddress)
      Gets the geo position and location information from an IP address if possible.
      static boolean getGeoLocation​(int logLevel, java.net.InetAddress ipAddress, java.util.function.BiFunction<GeoLocation,​java.lang.Exception,​java.lang.Void> callback)
      Gets the geo position and location information from an IP address if possible.
      static GeoLocation getGeoLocation​(java.net.InetAddress ipAddress)
      Gets the geo position and location information from an IP address if possible.
      static boolean getGeoLocation​(java.net.InetAddress ipAddress, java.util.function.BiFunction<GeoLocation,​java.lang.Exception,​java.lang.Void> callback)
      Gets the geo position and location information from an IP address if possible.
      static void main​(java.lang.String[] args)
      Test code.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getGeoLocation

        public static boolean getGeoLocation​(java.net.InetAddress ipAddress,
                                             java.util.function.BiFunction<GeoLocation,​java.lang.Exception,​java.lang.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,
                                             java.net.InetAddress ipAddress,
                                             java.util.function.BiFunction<GeoLocation,​java.lang.Exception,​java.lang.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​(java.net.InetAddress ipAddress)
                                          throws java.io.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:
        java.io.IOException - For I/O errors.
        JSONException - For JSON errors.
      • getGeoLocation

        public static GeoLocation getGeoLocation​(int logLevel,
                                                 java.net.InetAddress ipAddress)
                                          throws java.io.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:
        java.io.IOException - For I/O errors.
        JSONException - For JSON errors.
      • main

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