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). -
Field Summary
-
Constructor Summary
Constructors Constructor Description GeoLocation()
-
Method Summary
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()
-
Field Details
-
city
-
region
-
country
-
latitude
-
longitude
-
-
Constructor Details
-
GeoLocation
public GeoLocation()
-
-
Method Details
-
getLocationFromIp
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
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
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
-
setCity
-
getRegion
-
setRegion
-
getCountry
-
setCountry
-
getLatitude
-
setLatitude
-
getLongitude
-
setLongitude
-
toString
-
append
-