b7ed3367f2be269c922abda2926d8e43f7450232
[googlelatitude] / src / gps.cpp
1 #include "gps.h"
2
3 GpsMaemo5::GpsMaemo5(QObject *parent) : QObject(parent) {
4     latitude = 0;
5     longitude = 0;
6     accuracy = 0;
7
8     control = location_gpsd_control_get_default();
9     device = (LocationGPSDevice*) g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
10
11     g_signal_connect(device, "changed", G_CALLBACK(GpsMaemo5_changed), this);
12     g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_ACWP, NULL);
13     g_object_set(G_OBJECT(control), "preferred-interval", LOCATION_INTERVAL_120S, NULL);
14
15     location_gpsd_control_start(control);
16 }
17
18 void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps) {
19     if (device->fix) {
20         if (device->fix->fields) {
21             g_print("lat = %f, long = %f, eph = %f\n", gps->device->fix->latitude, gps->device->fix->longitude, gps->device->fix->eph/100.);
22             gps->latitude = gps->device->fix->latitude;
23             gps->longitude = gps->device->fix->longitude;
24             gps->accuracy = gps->device->fix->eph/100.;
25             emit gps->fix();
26         }
27     }
28 }