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_new("");
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\n", 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\n", 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);
71 hildon_gtk_window_set_progress_indicator(GTK_WINDOW(window), device->status == LOCATION_GPS_DEVICE_STATUS_NO_FIX);
74 if (device->cell_info) {
75 if (device->cell_info->flags & LOCATION_CELL_INFO_GSM_CELL_INFO_SET)
76 g_print ("Mobile Coutry Code GSM: %d\n", device->cell_info->gsm_cell_info.mcc);
78 if (device->cell_info->flags & LOCATION_CELL_INFO_WCDMA_CELL_INFO_SET)
79 g_print ("Mobile Coutry Code WCDMA: %d\n", device->cell_info->wcdma_cell_info.mcc);
82 gtk_label_set_text(info, msg->str);
83 //gtk_widget_show(GTK_WIDGET(info));
84 g_string_free(msg, TRUE);
88 on_gps_error (LocationGPSDevice *device, gpointer data)
90 g_error ("GPS error");
94 on_gps_stop (LocationGPSDevice *device, gpointer data)
96 g_warning ("GPS stopped");
100 on_gps_start (LocationGPSDevice *device, gpointer data)
102 g_warning ("GPS started");
105 int main (int argc, char **argv)
107 HildonProgram *program = NULL;
108 GtkWidget *picker_button = NULL;
110 GtkWidget *status_label;
111 GtkButton *start_button;
113 hildon_gtk_init (&argc, &argv);
114 LocationGPSDControl *control;
115 LocationGPSDevice *device;
117 program = hildon_program_get_instance ();
118 g_set_application_name("GPS tracker");
120 window = hildon_stackable_window_new ();
121 hildon_program_add_window (program, HILDON_WINDOW (window));
123 vbox = (void*)gtk_vbox_new(FALSE, 0);
125 /* Create a picker button */
126 picker_button = hildon_date_button_new (HILDON_SIZE_AUTO,
127 HILDON_BUTTON_ARRANGEMENT_VERTICAL);
129 /* Set a title to the button*/
130 hildon_button_set_title (HILDON_BUTTON (picker_button), "Pick a date");
132 start_button = GTK_BUTTON (hildon_gtk_button_new (HILDON_SIZE_THUMB_HEIGHT));
133 gtk_button_set_label (start_button, "Start");
134 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(start_button), FALSE, FALSE, 8);
135 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(picker_button), FALSE, FALSE, 0);
136 status_label = gtk_label_new("Hier kommt der Status hin\nUnd hier ist die 2. Zeile");
137 gtk_box_pack_start_defaults(GTK_BOX(vbox), status_label);
138 /* Add vbox to main window */
139 gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET(vbox));
141 g_signal_connect (G_OBJECT (window), "destroy",
142 G_CALLBACK (gtk_main_quit), NULL);
144 control = location_gpsd_control_get_default ();
145 hildon_banner_show_information(GTK_WIDGET(window), NULL, "Hi there!");
146 location_gpsd_control_start (control);
149 * Note that in real life one may want to use some other method and interval
150 * than LOCATION_METHOD_USER_SELECTED and LOCATION_INTERVAL_DEFAULT,
151 * respectively. For more information on possible values for these parameters
152 * please see liblocation online documentation.
154 g_object_set (G_OBJECT (control),
155 "preferred-method", LOCATION_METHOD_USER_SELECTED,
156 "preferred-interval", LOCATION_INTERVAL_DEFAULT,
159 device = g_object_new (LOCATION_TYPE_GPS_DEVICE, NULL);
161 g_signal_connect (control, "error", G_CALLBACK (on_gps_error), NULL);
162 g_signal_connect (control, "gpsd-running", G_CALLBACK (on_gps_start), NULL);
163 g_signal_connect (control, "gpsd-stopped", G_CALLBACK (on_gps_stop), NULL);
164 g_signal_connect (device, "changed", G_CALLBACK (on_gps_device_changed), status_label);
166 gtk_widget_show_all (GTK_WIDGET (window));
168 hildon_gtk_window_set_progress_indicator(GTK_WINDOW(window), 1);
171 location_gpsd_control_stop (control);
173 g_object_unref (device);
174 g_object_unref (control);