Maemo 5 liblocation minimalistic test application
Article Metadata
While more extended example with UI exists here: Qt for Maemo: Location Example sometimes we need a minimalistic test application for investigation purposes. This application simply prints out information obtained from liblocation to the console.
#include <QCoreApplication>
#include <QDebug>
extern "C" {
#include <location/location-gps-device.h>
#include <location/location-gpsd-control.h>
}
static void printLocationInfo(LocationGPSDevice *device, const char *label)
{
qDebug() << QString("%1:\n"
"time:\t%2\nept:\t%3\nlat:\t%4\nlong:\t%5\neph:\t%6\nspeed:\%7\neps:\t%8\ntrack:\t%9\nepd:\t%10\nsatellites:\t%11\n")
.arg(label)
.arg(device->fix->time)
.arg(device->fix->ept)
.arg(device->fix->latitude)
.arg(device->fix->longitude)
.arg(device->fix->eph)
.arg(device->fix->speed)
.arg(device->fix->eps)
.arg(device->fix->track)
.arg(device->fix->epd)
.arg(device->satellites_in_use);
}
static void changed(LocationGPSDevice *device, gpointer userdata)
{
Q_UNUSED(userdata);
printLocationInfo(device, "CHANGED");
}
static void connected(LocationGPSDevice *device, gpointer userdata)
{
Q_UNUSED(userdata);
printLocationInfo(device, "CONNECTED");
}
static void disconnected(LocationGPSDevice *device, gpointer userdata)
{
Q_UNUSED(userdata);
printLocationInfo(device, "DISCONNECTED");
}
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
LocationGPSDevice *device;
LocationGPSDControl *control;
g_type_init ();
control = location_gpsd_control_get_default();
if (control)
location_gpsd_control_start(control);
device = (LocationGPSDevice*)g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
if (device) {
g_signal_connect(device, "changed", G_CALLBACK(changed), 0);
g_signal_connect(device, "connected", G_CALLBACK(connected), 0);
g_signal_connect(device, "disconnected", G_CALLBACK(disconnected), 0);
}
int ret = app.exec();
if (device)
g_object_unref(device);
if (control)
location_gpsd_control_stop(control);
return ret;
}
Do not forget to add to your .pro file:
CONFIG += link_pkgconfig
PKGCONFIG += liblocation


Moderator note;- when expressed "on console" we would assume in the emulator. Which produces the standard location
To run this on a phone requires more code as the console will not open on many Symbian phones
Jim Gilmour