class FindLocation : Object { public static MainLoop main_loop = new MainLoop (); public FindLocation () { Environment.set_application_name ("Find Location"); } public async void seek () { GClue.Manager manager; GClue.Client client; string? client_path = null; try { manager = yield GClue.ManagerProxy.create_for_bus (GLib.BusType.SYSTEM, GLib.DBusProxyFlags.NONE, "org.freedesktop.GeoClue2", "/org/freedesktop/GeoClue2/Manager"); } catch (Error e) { error ("Failed to connect to GeoClue2 Manager service: %s", e.message); } try { yield manager.call_get_client (out client_path); } catch (Error e) { error ("Failed to connect to GeoClue2 Manager service: %s", e.message); } if (client_path == null) { error ("The client path is not set"); } stdout.printf ("Client object: %s\n", client_path); try { client = yield GClue.ClientProxy.create_for_bus (GLib.BusType.SYSTEM, GLib.DBusProxyFlags.NONE, "org.freedesktop.GeoClue2", client_path); } catch (Error e) { error ("Failed to connect to GeoClue2 Client service: %s", e.message); } client.location_updated.connect (on_location_updated); try { yield client.call_start (); } catch (Error e) { error ("Failed to start client: %s", e.message); } } public async void on_location_updated (string old_path, string new_path) { GClue.Location location; try { location = yield GClue.LocationProxy.create_for_bus (GLib.BusType.SYSTEM, GLib.DBusProxyFlags.NONE, "org.freedesktop.GeoClue2", new_path); } catch (Error e) { error ("Failed to connect to GeoClue2 Location service: %s", e.message); } stdout.printf ("Latitude: %f\nLongitude: %f\nAccuracy (in meters): %f\n", location.latitude, location.longitude, location.accuracy); string desc = location.description; if (desc != null) stdout.printf ("Description: %s\n", desc); main_loop.quit (); } public static void main () { var fl = new FindLocation (); fl.seek.begin (); main_loop.run (); } }