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_print ("GPS status: %d\n", device->status);
70 hildon_gtk_window_set_progress_indicator(GTK_WINDOW(window), device->status == LOCATION_GPS_DEVICE_STATUS_NO_FIX);
73 if (device->cell_info) {
74 if (device->cell_info->flags & LOCATION_CELL_INFO_GSM_CELL_INFO_SET)
75 g_print ("Mobile Coutry Code GSM: %d\n", device->cell_info->gsm_cell_info.mcc);
77 if (device->cell_info->flags & LOCATION_CELL_INFO_WCDMA_CELL_INFO_SET)
78 g_print ("Mobile Coutry Code WCDMA: %d\n", device->cell_info->wcdma_cell_info.mcc);
81 gtk_label_set_text(info, msg->str);
82 //gtk_widget_show(GTK_WIDGET(info));
83 g_string_free(msg, TRUE);
87 on_gps_error (LocationGPSDevice *device, gpointer data)
89 g_error ("GPS error");
93 on_gps_stop (LocationGPSDevice *device, gpointer data)
95 g_warning ("GPS stopped");
99 on_gps_start (LocationGPSDevice *device, gpointer data)
101 g_warning ("GPS started");
104 int main (int argc, char **argv)
106 HildonProgram *program = NULL;
107 GtkWidget *picker_button = NULL;
109 GtkWidget *status_label;
110 GtkButton *start_button;
112 hildon_gtk_init (&argc, &argv);
113 LocationGPSDControl *control;
114 LocationGPSDevice *device;
116 program = hildon_program_get_instance ();
117 g_set_application_name("GPS tracker");
119 window = hildon_stackable_window_new ();
120 hildon_program_add_window (program, HILDON_WINDOW (window));
122 vbox = (void*)gtk_vbox_new(FALSE, 0);
124 /* Create a picker button */
125 picker_button = hildon_date_button_new (HILDON_SIZE_AUTO,
126 HILDON_BUTTON_ARRANGEMENT_VERTICAL);
128 /* Set a title to the button*/
129 hildon_button_set_title (HILDON_BUTTON (picker_button), "Pick a date");
131 start_button = GTK_BUTTON (hildon_gtk_button_new (HILDON_SIZE_THUMB_HEIGHT));
132 gtk_button_set_label (start_button, "Start");
133 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(start_button), FALSE, FALSE, 8);
134 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(picker_button), FALSE, FALSE, 0);
135 status_label = gtk_label_new("Hier kommt der Status hin\nUnd hier ist die 2. Zeile");
136 gtk_box_pack_start_defaults(GTK_BOX(vbox), status_label);
137 /* Add vbox to main window */
138 gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET(vbox));
140 g_signal_connect (G_OBJECT (window), "destroy",
141 G_CALLBACK (gtk_main_quit), NULL);
143 control = location_gpsd_control_get_default ();
144 hildon_banner_show_information(GTK_WIDGET(window), NULL, "Hi there!");
145 location_gpsd_control_start (control);
148 * Note that in real life one may want to use some other method and interval
149 * than LOCATION_METHOD_USER_SELECTED and LOCATION_INTERVAL_DEFAULT,
150 * respectively. For more information on possible values for these parameters
151 * please see liblocation online documentation.
153 g_object_set (G_OBJECT (control),
154 "preferred-method", LOCATION_METHOD_USER_SELECTED,
155 "preferred-interval", LOCATION_INTERVAL_DEFAULT,
158 device = g_object_new (LOCATION_TYPE_GPS_DEVICE, NULL);
160 g_signal_connect (control, "error", G_CALLBACK (on_gps_error), NULL);
161 g_signal_connect (control, "gpsd-running", G_CALLBACK (on_gps_start), NULL);
162 g_signal_connect (control, "gpsd-stopped", G_CALLBACK (on_gps_stop), NULL);
163 g_signal_connect (device, "changed", G_CALLBACK (on_gps_device_changed), status_label);
165 gtk_widget_show_all (GTK_WIDGET (window));
167 hildon_gtk_window_set_progress_indicator(GTK_WINDOW(window), 1);
170 location_gpsd_control_stop (control);
172 g_object_unref (device);
173 g_object_unref (control);