×
Namespaces

Variants
Actions

Maemo 5 liblocation minimalistic test application

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Compatibility
Platform(s):
Symbian
Article
Created: divanov (20 May 2010)
Last edited: hamishwillee (11 Oct 2012)

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
This page was last modified on 11 October 2012, at 04:17.
40 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×