Top | ![]() |
![]() |
![]() |
![]() |
A GWeatherLocation represents a "location" of some type known to libgweather; anything from a single weather station to the entire world. See GWeatherLocationLevel for information about how the hierarchy of locations works.
GWeatherLocation *
gweather_location_get_world (void
);
Obtains the shared GWeatherLocation of type GWEATHER_LOCATION_WORLD
,
representing a hierarchy containing all of the locations from
Locations.xml.
Prior to version 40 no reference was returned.
a GWEATHER_LOCATION_WORLD
location, or NULL
if Locations.xml could not be found or could not be parsed.
[allow-none][transfer full]
GWeatherLocation * gweather_location_new_detached (const char *name
,const char *icao
,gdouble latitude
,gdouble longitude
);
Construct a new location from the given data, supplementing any missing information from the static database.
GWeatherLocation *
gweather_location_ref (GWeatherLocation *loc
);
Adds 1 to loc
's reference count.
void
gweather_location_unref (GWeatherLocation *loc
);
Subtracts 1 from loc
's reference count, and frees it if the
reference count reaches 0.
GVariant *
gweather_location_serialize (GWeatherLocation *loc
);
Transforms a GWeatherLocation into a GVariant, in a way that
calling gweather_location_deserialize()
will hold an equivalent
GWeatherLocation.
The resulting variant can then be stored into GSettings or on disk.
This call is only valid for cities, weather stations and detached
locations.
The format of the resulting GVariant is private to libgweather,
and it is subject to change. You should use the "v" format in GSettings,
to ensure maximum compatibility with future versions of the library.
GWeatherLocation * gweather_location_deserialize (GWeatherLocation *world
,GVariant *serialized
);
This call undoes the effect of gweather_location_serialize()
, that
is, it turns a GVariant into a GWeatherLocation. The conversion
happens in the context of world
(i.e, for a city or weather station,
the resulting location will be attached to a administrative division,
country and region as appropriate).
world |
a world-level GWeatherLocation |
|
serialized |
the GVariant representing the GWeatherLocation |
gboolean gweather_location_equal (GWeatherLocation *one
,GWeatherLocation *two
);
Compares two GWeatherLocation and sees if they represent the same place. It is only legal to call this for cities, weather stations or detached locations. Note that this function only checks for geographical characteristics, such as coordinates and METAR code. It is still possible that the two locations belong to different worlds (in which case care must be taken when passing them GWeatherLocationEntry and GWeatherInfo), or if one is them is detached it could have a custom name.
GWeatherLocation * gweather_location_find_by_station_code (GWeatherLocation *world
,const gchar *station_code
);
Retrieves the weather station identifier by station_code
.
Note that multiple instances of the same weather station can exist
in the database, and this function will return any of them, so this
not usually what you want.
See gweather_location_deserialize()
to recover a stored GWeatherLocation.
Prior to version 40 no reference was returned.
a weather station level GWeatherLocation for station_code
,
or NULL
if none exists in the database.
[transfer full]
GWeatherLocation * gweather_location_find_nearest_city (GWeatherLocation *loc
,double lat
,double lon
);
Finds the nearest city to the passed latitude and
longitude, among the descendants of loc
.
loc
must be at most a GWEATHER_LOCATION_ADM1
location.
This restriction may be lifted in a future version.
Note that this function does not check if (lat
, lon
) fall inside
loc
, or are in the same region and timezone as the return value.
loc |
The parent location, which will be searched recursively. |
[allow-none] |
lat |
Latitude, in degrees |
|
lon |
Longitude, in degrees |
the city closest to (lat
, lon
), in the
region or administrative district of loc
.
[transfer full]
Since: 3.12
gboolean (*GWeatherFilterFunc) (GWeatherLocation *location
,gpointer user_data
);
GWeatherLocation * gweather_location_find_nearest_city_full (GWeatherLocation *loc
,double lat
,double lon
,GWeatherFilterFunc func
,gpointer user_data
,GDestroyNotify destroy
);
Finds the nearest city to the passed latitude and
longitude, among the descendants of loc
.
Supports the use of own filter function to filter out locations. Geocoding should be done on the application side if needed.
loc
must be at most a GWEATHER_LOCATION_ADM1
location.
This restriction may be lifted in a future version.
loc |
The parent location, which will be searched recursively. |
[allow-none] |
lat |
Latitude, in degrees |
|
lon |
Longitude, in degrees |
|
func |
returns true to continue check for the location and false to filter the location out. |
[scope notified][allow-none] |
user_data |
for customization |
|
destroy |
to destroy user_data |
the city closest to (lat
, lon
), in the
region or administrative district of loc
with validation of filter function.
[transfer full]
Since: 3.12
void gweather_location_detect_nearest_city (GWeatherLocation *loc
,double lat
,double lon
,GCancellable *cancellable
,GAsyncReadyCallback callback
,gpointer user_data
);
Initializes geocode reversing to find place for (lat
, lon
) coordinates. Calls the callback
function passed by user when the result is ready.
loc
must be at most a GWEATHER_LOCATION_ADM1
location.
This restriction may be lifted in a future version.
loc |
The parent location, which will be searched recursively. |
[allow-none] |
lat |
Latitude, in degrees |
|
lon |
Longitude, in degrees |
|
cancellable |
optional, NULL to ignore |
|
callback |
callback function for GAsyncReadyCallback argument for GAsyncResult |
|
user_data |
user data passed to |
Since: 3.12
GWeatherLocation * gweather_location_detect_nearest_city_finish (GAsyncResult *result
,GError **error
);
GWeatherLocationLevel
gweather_location_get_level (GWeatherLocation *loc
);
Gets loc
's level, from GWEATHER_LOCATION_WORLD
, to
GWEATHER_LOCATION_WEATHER_STATION
.
GWeatherLocation *
gweather_location_get_parent (GWeatherLocation *loc
);
Gets loc
's parent location.
Prior to version 40 no reference was returned.
loc
's parent, or NULL
if loc
is a GWEATHER_LOCATION_WORLD
node.
[transfer full][allow-none]
GWeatherLocation **
gweather_location_get_children (GWeatherLocation *loc
);
gweather_location_get_children
has been deprecated since version 40. and should not be used in newly-written code.
Use gweather_location_next_child()
instead to avoid high
memory consumption
Gets an array of loc
's children; this is owned by loc
and will
not remain valid if loc
is freed.
const char *
gweather_location_get_name (GWeatherLocation *loc
);
Gets loc
's name, localized into the current language.
const char *
gweather_location_get_sort_name (GWeatherLocation *loc
);
Gets loc
's "sort name", which is the name after having
g_utf8_normalize()
(with G_NORMALIZE_ALL
) and g_utf8_casefold()
called on it. You can use this to sort locations, or to comparing
user input against a location name.
const char *
gweather_location_get_english_name (GWeatherLocation *loc
);
Gets loc
's English name.
Since: 3.36
gboolean
gweather_location_has_coords (GWeatherLocation *loc
);
Checks if loc
has valid latitude and longitude.
void gweather_location_get_coords (GWeatherLocation *loc
,double *latitude
,double *longitude
);
Gets loc
's coordinates; you must check
gweather_location_has_coords()
before calling this.
double gweather_location_get_distance (GWeatherLocation *loc
,GWeatherLocation *loc2
);
Determines the distance in kilometers between loc
and loc2
.
const char *
gweather_location_get_country (GWeatherLocation *loc
);
Gets the ISO 3166 country code of loc
(or NULL
if loc
is a
region- or world-level location)
GWeatherTimezone *
gweather_location_get_timezone (GWeatherLocation *loc
);
Gets the timezone associated with loc
, if known.
The timezone is owned either by loc
or by one of its parents.
FIXME.
GWeatherTimezone **
gweather_location_get_timezones (GWeatherLocation *loc
);
Gets an array of all timezones associated with any location under
loc
. You can use gweather_location_free_timezones()
to free this
array.
const char *
gweather_location_get_code (GWeatherLocation *loc
);
Gets the METAR station code associated with a
GWEATHER_LOCATION_WEATHER_STATION
location.
char *
gweather_location_get_city_name (GWeatherLocation *loc
);
For a GWEATHER_LOCATION_CITY
or GWEATHER_LOCATION_DETACHED
location,
this is equivalent to gweather_location_get_name()
.
For a GWEATHER_LOCATION_WEATHER_STATION
location, it is equivalent to
calling gweather_location_get_name()
on the location's parent. For
other locations it will return NULL
.
char *
gweather_location_get_country_name (GWeatherLocation *loc
);
Gets the country name of loc.
For a GWEATHER_LOCATION_COUNTRY
location, this is equivalent to
gweather_location_get_name()
.
For a GWEATHER_LOCATION_REGION
and GWEATHER_LOCATION_WORLD location it
will return NULL
.
For other locations it will find the parent GWEATHER_LOCATION_COUNTRY
and return its name.
The size/scope of a particular GWeatherLocation.
Locations form a hierarchy, with a GWEATHER_LOCATION_WORLD
location at the top, divided into regions or countries, and so on.
Countries may or may not be divided into "adm1"s, and "adm1"s may
or may not be divided into "adm2"s. A city will have at least one,
and possibly several, weather stations inside it. Weather stations
will never appear outside of cities.
Building a database with gweather_location_get_world()
will never
create detached instances, but deserializing might.
A location representing the entire world. |
||
A location representing a continent or other top-level region. |
||
A location representing a "country" (or other geographic unit that has an ISO-3166 country code) |
||
A location representing a "first-level administrative division"; ie, a state, province, or similar division. |
||
A location representing a city |
||
A location representing a weather station. |
||
A location that is detached from the database, for example because it was loaded from external storage and could not be fully recovered. The parent of this location is the nearest weather station. |
||
A location representing a named or special timezone in the world, such as UTC |