0

I want to access the city name and add it to a Gtk.Label. This is how I try to do it.

Can anyone tell me what is wrong with my code? Or suggest some other way to get the city name?

public class Epoch.LabelsGrid : Gtk.Grid {
    public Gtk.Label face1_label;
    public Gtk.Label face2_label;
    public Gtk.Label face3_label;
    public Gtk.Label face4_label;
    
    private GWeather.Location location;
    
    construct {
        get_location.begin ();
        
        face1_label = new Gtk.Label ("");
        face1_label.label = location.get_city_name ();
        face1_label.halign = Gtk.Align.CENTER;
        face1_label.hexpand = true;
        face1_label.margin_top = 6;
        face1_label.set_ellipsize (END);
        face1_label.set_max_width_chars (12);
    }
    
    public async void get_location () {
        try {
            var simple = yield new GClue.Simple ("com.github.danrabbit.nimbus", GClue.AccuracyLevel.CITY, null);

            simple.notify["location"].connect (() => {
                on_location_updated (simple.location.latitude, simple.location.longitude);
            });

            on_location_updated (simple.location.latitude, simple.location.longitude);
        } catch (Error e) {
            warning ("Failed to connect to GeoClue2 service: %s", e.message);
            return;
        }
    }
    
    public void on_location_updated (double latitude, double longitude) {
        location = GWeather.Location.get_world ();
        location = location.find_nearest_city (latitude, longitude);
    }
}

This is the error displayed while compiling:

[1/2] Compiling C object 'com.github.Suzie97.epoch@exe/meson-generated_src_Widgets_Labels.c.o'.
FAILED: com.github.Suzie97.epoch@exe/meson-generated_src_Widgets_Labels.c.o 
cc -Icom.github.Suzie97.epoch@exe -I. -I.. -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/libgeoclue-2.0 -I/usr/include/libgweather-3.0 -I/usr/include/geocode-glib-1.0 -I/usr/include/libsoup-2.4 -I/usr/include/libxml2 -I/usr/include/granite -I/usr/include/gee-0.8 -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -w -g '-DGETTEXT_PACKAGE="com.github.Suzie97.epoch"' -pthread  -MD -MQ 'com.github.Suzie97.epoch@exe/meson-generated_src_Widgets_Labels.c.o' -MF 'com.github.Suzie97.epoch@exe/meson-generated_src_Widgets_Labels.c.o.d' -o 'com.github.Suzie97.epoch@exe/meson-generated_src_Widgets_Labels.c.o' -c 'com.github.Suzie97.epoch@exe/src/Widgets/Labels.c'
In file included from com.github.Suzie97.epoch@exe/src/Widgets/Labels.c:28:0:
/usr/include/libgweather-3.0/libgweather/gweather.h:25:2: error: #error "libgweather should only be used if you understand that it's subject to change, and is not supported as a fixed API/ABI or as part of the platform"
 #error "libgweather should only be used if you understand that it's subject to change, and is not supported as a fixed API/ABI or as part of the platform"
  ^~~~~
ninja: build stopped: subcommand failed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.