hamlocator/src/location.vala

30 wiersze
863 B
Vala

// Taken from https://github.com/ryonakano/atlas/blob/main/src/GeoClue.vala
namespace Hamlocator {
public struct LocationResult {
public GClue.Location? loc;
public string? err;
}
public class Location : Object {
private GClue.Simple? simple;
public Location () {
}
public async LocationResult get_current_location () {
if (simple == null) {
try {
simple = yield new GClue.Simple ("eu.fl9.hamlocator", GClue.AccuracyLevel.NEIGHBORHOOD, null);
} catch (Error e) {
warning ("Failed to connect to GeoClue2 service: %s", e.message);
return LocationResult() { err = e.message };
}
}
return LocationResult() { loc = simple.get_location() };
}
}
}