3 #include <hildon/hildon.h>
4 #include <location/location-gpsd-control.h>
5 #include <location/location-gps-device.h>
6 #include <location/location-misc.h>
7 #include <location/location-distance-utils.h>
10 on_gps_device_changed (LocationGPSDevice *device, gpointer data)
12 GtkLabel *info = (GtkLabel*)data;
17 msg = g_string_new("");
19 if (device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET) {
20 g_print ("time = %f\n", device->fix->time);
21 g_string_append_printf(msg, "time = %f\n", device->fix->time);
24 if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) {
25 g_print ("lat = %f, long = %f\n",
26 device->fix->latitude,
27 device->fix->longitude);
28 g_string_append_printf (msg, "lat = %f, long = %f\n",
29 device->fix->latitude,
30 device->fix->longitude);
33 if (device->fix->fields & LOCATION_GPS_DEVICE_ALTITUDE_SET) {
34 g_print ("alt = %f\n", device->fix->altitude);
35 g_string_append_printf (msg, "alt = %f\n", device->fix->altitude);
38 if (device->fix->fields & LOCATION_GPS_DEVICE_SPEED_SET) {
39 g_print ("speed = %f\n", device->fix->speed);
40 g_string_append_printf (msg, "speed = %f\n", device->fix->speed);
43 if (device->fix->fields & LOCATION_GPS_DEVICE_TRACK_SET) {
44 g_print ("track = %f\n", device->fix->track);
45 g_string_append_printf (msg, "track = %f\n", device->fix->track);
48 if (device->fix->fields & LOCATION_GPS_DEVICE_CLIMB_SET) {
49 g_print ("climb = %f\n", device->fix->climb);
50 g_string_append_printf (msg, "climb = %f\n", device->fix->climb);
53 g_print ("Accuracy values:\n");
54 g_print ("\tept = %e, eph = %e, epv = %e, epd = %e, "
55 "eps = %e, epc = %e\n",
64 g_print ("Satellites in view: %d\n", device->satellites_in_view);
65 g_print ("Satellites in use: %d\n", device->satellites_in_use);
66 g_print ("GPS status: %d\n", device->status);
68 if (device->cell_info) {
69 if (device->cell_info->flags & LOCATION_CELL_INFO_GSM_CELL_INFO_SET)
70 g_print ("Mobile Coutry Code GSM: %d\n", device->cell_info->gsm_cell_info.mcc);
72 if (device->cell_info->flags & LOCATION_CELL_INFO_WCDMA_CELL_INFO_SET)
73 g_print ("Mobile Coutry Code WCDMA: %d\n", device->cell_info->wcdma_cell_info.mcc);
76 gtk_label_set_text(info, msg->str);
77 //gtk_widget_show(GTK_WIDGET(info));
78 g_string_free(msg, TRUE);
82 on_gps_error (LocationGPSDevice *device, gpointer data)
84 g_error ("GPS error");
88 on_gps_stop (LocationGPSDevice *device, gpointer data)
90 g_warning ("GPS stopped");
94 on_gps_start (LocationGPSDevice *device, gpointer data)
96 g_warning ("GPS started");
99 int main (int argc, char **argv)
101 HildonProgram *program = NULL;
102 GtkWidget *window = NULL;
103 GtkWidget *picker_button = NULL;
105 GtkWidget *status_label;
107 hildon_gtk_init (&argc, &argv);
108 LocationGPSDControl *control;
109 LocationGPSDevice *device;
111 program = hildon_program_get_instance ();
112 g_set_application_name("GPS tracker");
114 window = hildon_stackable_window_new ();
115 hildon_program_add_window (program, HILDON_WINDOW (window));
117 vbox = (void*)gtk_vbox_new(TRUE, 8);
119 /* Create a picker button */
120 picker_button = hildon_date_button_new (HILDON_SIZE_AUTO,
121 HILDON_BUTTON_ARRANGEMENT_VERTICAL);
123 /* Set a title to the button*/
124 hildon_button_set_title (HILDON_BUTTON (picker_button), "Pick a date");
126 gtk_box_pack_start(GTK_BOX(vbox), picker_button, FALSE, FALSE, 0);
127 status_label = gtk_label_new("Hier kommt der Status hin\nUnd hier ist die 2. Zeile");
128 gtk_box_pack_start_defaults(GTK_BOX(vbox), status_label);
129 /* Add vbox to main window */
130 gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET(vbox));
132 g_signal_connect (G_OBJECT (window), "destroy",
133 G_CALLBACK (gtk_main_quit), NULL);
135 control = location_gpsd_control_get_default ();
136 location_gpsd_control_start (control);
139 * Note that in real life one may want to use some other method and interval
140 * than LOCATION_METHOD_USER_SELECTED and LOCATION_INTERVAL_DEFAULT,
141 * respectively. For more information on possible values for these parameters
142 * please see liblocation online documentation.
144 g_object_set (G_OBJECT (control),
145 "preferred-method", LOCATION_METHOD_USER_SELECTED,
146 "preferred-interval", LOCATION_INTERVAL_DEFAULT,
149 device = g_object_new (LOCATION_TYPE_GPS_DEVICE, NULL);
151 g_signal_connect (control, "error", G_CALLBACK (on_gps_error), NULL);
152 g_signal_connect (control, "gpsd-running", G_CALLBACK (on_gps_start), NULL);
153 g_signal_connect (control, "gpsd-stopped", G_CALLBACK (on_gps_stop), NULL);
154 g_signal_connect (device, "changed", G_CALLBACK (on_gps_device_changed), status_label);
156 gtk_widget_show_all (GTK_WIDGET (window));
160 location_gpsd_control_stop (control);
162 g_object_unref (device);
163 g_object_unref (control);