Class GeoLocation

java.lang.Object
net.sf.basedb.util.GeoLocation

public class GeoLocation extends Object
Utility class for geographic location.
Since:
3.12
Author:
nicklas
  • Field Details

    • city

      private String city
    • region

      private String region
    • country

      private String country
    • latitude

      private Float latitude
    • longitude

      private Float longitude
  • Constructor Details

    • GeoLocation

      public GeoLocation()
  • Method Details

    • getLocationFromIp

      public static GeoLocation getLocationFromIp(String ip)
      Try to convert the given ip address to a location. This will query the 'freegeoip' server specified in base.config. The default is ''. If this has been disabled or if the location is unknown, null is returned.
    • getURLToMap

      public static String getURLToMap(Float latitude, Float longitude)
      Get an URL that opens a map marking the given position. A link template must have been configured in base.config (geolocation.maptemplate). Use {LAT} and {LONG} as placeholders for the latitude and longitude.
      Parameters:
      latitude - The latitude of the location
      longitude - The longitude of the location
      Returns:
      A link or null if either of the parameters is null
    • fromJson

      public static GeoLocation fromJson(org.json.simple.JSONObject json)
      Convert JSON data from freegeoip to a GeoLocation instance. The JSON must contain at least one of "city", "region_name" or "country_name".
      Returns:
      A location object or null if there is no data
    • getCity

      public String getCity()
    • setCity

      public void setCity(String city)
    • getRegion

      public String getRegion()
    • setRegion

      public void setRegion(String region)
    • getCountry

      public String getCountry()
    • setCountry

      public void setCountry(String country)
    • getLatitude

      public Float getLatitude()
    • setLatitude

      public void setLatitude(Float latitude)
    • getLongitude

      public Float getLongitude()
    • setLongitude

      public void setLongitude(Float longitude)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • append

      private void append(StringBuilder sb, String s)