14 Oct 2015 zeenix   » (Journeyer)

Geoclue convenience library just got even simpler

After writing the blog post about the new Geoclue convenience library, I felt that while the helper API was really simple for single-shot usage, it still wasn't as simple as it should be for most applications, that would need to monitor location updates. They'll still need to make async calls (they could do it synchronously too but that is hardly ever a good idea) to create proxy for location objects on location updates.

So yesterday, I came up with even simpler API that should make interacting with Geoclue as simple as possible. I'll demonstrate through some gjs code that simply awaits for location updates forever and prints the location on console each time there is a location update:

const Geoclue = imports.gi.Geoclue;
const MainLoop = imports.mainloop;

let onLocationUpdated = function(simple) {
let location = simple.get_location ();

print("Location: " +
location.latitude + "," +
location.longitude);
};

let onSimpleReady = function(object, result) {
let simple = Geoclue.Simple.new_finish (result);
simple.connect("notify::location", onLocationUpdated);

onLocationUpdated (simple);
};

Geoclue.Simple.new ("geoclue-where-am-i", /* Let's cheat */
Geoclue.AccuracyLevel.EXACT,
null,
onSimpleReady);

MainLoop.run('');


Yup, that easy! If I had chosen to use the synchronous API, it would be even simpler. I have already provided a patch for Maps to take advantage of this and I'm planning to provide patches for other apps too.

Syndicated 2015-10-14 17:30:00 (Updated 2015-10-15 16:45:46) from zeenix

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!