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>
9 static GtkWidget *window = NULL;
12 on_gps_device_changed (LocationGPSDevice *device, gpointer data)
14 GtkLabel *info = (GtkLabel*)data;
19 msg = g_string_sized_new (512);
21 if (device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET) {
22 g_print ("time = %f\n", device->fix->time);
23 g_string_append_printf(msg, "time = %f\n", device->fix->time);
26 if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) {
27 g_print ("lat = %f, long = %f\n",
28 device->fix->latitude,
29 device->fix->longitude);
30 g_string_append_printf (msg, "lat = %f, long = %f\n",
31 device->fix->latitude,
32 device->fix->longitude);
35 if (device->fix->fields & LOCATION_GPS_DEVICE_ALTITUDE_SET) {
36 g_print ("alt = %f\n", device->fix->altitude);
37 g_string_append_printf (msg, "alt = %f\n", device->fix->altitude);
40 if (device->fix->fields & LOCATION_GPS_DEVICE_SPEED_SET) {
41 g_print ("speed = %f\n", device->fix->speed);
42 g_string_append_printf (msg, "speed = %f, ", device->fix->speed);
45 if (device->fix->fields & LOCATION_GPS_DEVICE_TRACK_SET) {
46 g_print ("track = %f\n", device->fix->track);
47 g_string_append_printf (msg, "track = %f, ", device->fix->track);
50 if (device->fix->fields & LOCATION_GPS_DEVICE_CLIMB_SET) {
51 g_print ("climb = %f\n", device->fix->climb);
52 g_string_append_printf (msg, "climb = %f\n", device->fix->climb);
55 g_print ("Accuracy values:\n");
56 g_print ("\tept = %e, eph = %e, epv = %e, epd = %e, "
57 "eps = %e, epc = %e\n",
66 g_print ("Satellites in view: %d\n", device->satellites_in_view);
67 g_print ("Satellites in use: %d\n", device->satellites_in_use);
68 g_string_append_printf (msg, "Satellites = % 2d/% 2d\n", device->satellites_in_use, device->satellites_in_view);
69 g_print ("GPS status: %d\n", device->status);
70 g_string_append_printf (msg, "GPS status: %d\n", device->status);
72 hildon_gtk_window_set_progress_indicator(GTK_WINDOW(window), device->status == LOCATION_GPS_DEVICE_STATUS_NO_FIX);
75 if (device->cell_info) {
76 if (device->cell_info->flags & LOCATION_CELL_INFO_GSM_CELL_INFO_SET)
77 g_print ("Mobile Coutry Code GSM: %d\n", device->cell_info->gsm_cell_info.mcc);
79 if (device->cell_info->flags & LOCATION_CELL_INFO_WCDMA_CELL_INFO_SET)
80 g_print ("Mobile Coutry Code WCDMA: %d\n", device->cell_info->wcdma_cell_info.mcc);
83 gtk_label_set_text(info, msg->str);
84 //gtk_widget_show(GTK_WIDGET(info));
85 g_string_free(msg, TRUE);
89 on_gps_error (LocationGPSDevice *device, gpointer data)
91 g_error ("GPS error");
95 on_gps_stop (LocationGPSDevice *device, gpointer data)
97 g_warning ("GPS stopped");
101 on_gps_start (LocationGPSDevice *device, gpointer data)
103 g_warning ("GPS started");
106 int main (int argc, char **argv)
108 HildonProgram *program = NULL;
109 GtkWidget *picker_button = NULL;
111 GtkWidget *status_label;
112 GtkButton *start_button;
114 hildon_gtk_init (&argc, &argv);
115 LocationGPSDControl *control;
116 LocationGPSDevice *device;
118 program = hildon_program_get_instance ();
119 g_set_application_name("GPS tracker");
121 window = hildon_stackable_window_new ();
122 hildon_program_add_window (program, HILDON_WINDOW (window));
124 vbox = (void*)gtk_vbox_new(FALSE, 0);
126 /* Create a picker button */
127 picker_button = hildon_date_button_new (HILDON_SIZE_AUTO,
128 HILDON_BUTTON_ARRANGEMENT_VERTICAL);
130 /* Set a title to the button*/
131 hildon_button_set_title (HILDON_BUTTON (picker_button), "Pick a date");
133 start_button = GTK_BUTTON (hildon_gtk_button_new (HILDON_SIZE_THUMB_HEIGHT));
134 gtk_button_set_label (start_button, "Start");
135 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(start_button), FALSE, FALSE, 8);
136 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(picker_button), FALSE, FALSE, 0);
137 status_label = gtk_label_new("Hier kommt der Status hin\nUnd hier ist die 2. Zeile");
138 gtk_box_pack_start_defaults(GTK_BOX(vbox), status_label);
139 /* Add vbox to main window */
140 gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET(vbox));
142 g_signal_connect (G_OBJECT (window), "destroy",
143 G_CALLBACK (gtk_main_quit), NULL);
145 control = location_gpsd_control_get_default ();
146 hildon_banner_show_information(GTK_WIDGET(window), NULL, "Hi there!");
147 location_gpsd_control_start (control);
150 * Note that in real life one may want to use some other method and interval
151 * than LOCATION_METHOD_USER_SELECTED and LOCATION_INTERVAL_DEFAULT,
152 * respectively. For more information on possible values for these parameters
153 * please see liblocation online documentation.
155 g_object_set (G_OBJECT (control),
156 "preferred-method", LOCATION_METHOD_USER_SELECTED,
157 "preferred-interval", LOCATION_INTERVAL_DEFAULT,
160 device = g_object_new (LOCATION_TYPE_GPS_DEVICE, NULL);
162 g_signal_connect (control, "error", G_CALLBACK (on_gps_error), NULL);
163 g_signal_connect (control, "gpsd-running", G_CALLBACK (on_gps_start), NULL);
164 g_signal_connect (control, "gpsd-stopped", G_CALLBACK (on_gps_stop), NULL);
165 g_signal_connect (device, "changed", G_CALLBACK (on_gps_device_changed), status_label);
167 gtk_widget_show_all (GTK_WIDGET (window));
169 hildon_gtk_window_set_progress_indicator(GTK_WINDOW(window), 1);
172 location_gpsd_control_stop (control);
174 g_object_unref (device);
175 g_object_unref (control);