Package net.sf.basedb.util
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
GeoLocation.ResponseFilter
We only accept "200" status response, "application/json" content type and not more than 1K bytes (should be a lot less under normal operations).
-
Constructor Summary
Constructors Constructor Description GeoLocation()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
append(StringBuilder sb, String s)
static GeoLocation
fromJson(org.json.simple.JSONObject json)
Convert JSON data from freegeoip to a GeoLocation instance.String
getCity()
String
getCountry()
Float
getLatitude()
static GeoLocation
getLocationFromIp(String ip)
Try to convert the given ip address to a location.Float
getLongitude()
String
getRegion()
static String
getURLToMap(Float latitude, Float longitude)
Get an URL that opens a map marking the given position.void
setCity(String city)
void
setCountry(String country)
void
setLatitude(Float latitude)
void
setLongitude(Float longitude)
void
setRegion(String region)
String
toString()
-
-
-
Method Detail
-
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 locationlongitude
- 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)
-
append
private void append(StringBuilder sb, String s)
-
-