Package net.sf.basedb.util
Class GeoLocation
java.lang.Object
net.sf.basedb.util.GeoLocation
Utility class for geographic location.
- Since:
- 3.12
- Author:
- nicklas
-
Nested Class Summary
Modifier and TypeClassDescription(package private) static class
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
-
Method Summary
Modifier and TypeMethodDescriptionprivate void
append
(StringBuilder sb, String s) static GeoLocation
fromJson
(org.json.simple.JSONObject json) Convert JSON data from freegeoip to a GeoLocation instance.getCity()
static GeoLocation
Try to convert the given ip address to a location.static String
getURLToMap
(Float latitude, Float longitude) Get an URL that opens a map marking the given position.void
void
setCountry
(String country) void
setLatitude
(Float latitude) void
setLongitude
(Float longitude) void
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
-