tizen 2.4 release
[framework/uifw/elementary.git] / src / examples / location_example_01.c
1 //Compile with:
2 //gcc -o location_example_01 location_example_01.c -g `pkg-config --cflags --libs elementary elocation`
3
4 #include <Elementary.h>
5 #ifdef ELM_ELOCATION
6 #include <Elocation.h>
7 #endif
8
9 static Evas_Object *label, *win;
10
11 #ifdef ELM_ELOCATION
12 static void
13 _print_position(Elocation_Position *position)
14 {
15    char buffer[1024];
16
17    if (!position) return;
18    snprintf(buffer, sizeof(buffer),
19             "<b>GeoClue position reply with data from timestamp</b> %i<br/>"
20             "<b>Latitude:</b> %f<br/>"
21             "<b>Longitude:</b> %f<br/>"
22             "<b>Altitude:</b> %f<br/>"
23             "<b>Accuracy level:</b> %i<br/>"
24             "<b>Accuracy horizontal:</b> %f<br/>"
25             "<b>Accuracy vertical:</b> %f",
26             position->timestamp, position->latitude, position->longitude,
27             position->altitude, position->accur->level,
28             position->accur->horizontal, position->accur->vertical);
29    elm_object_text_set(label, buffer);
30 }
31
32 static Eina_Bool
33 _position_changed(void *data, int ev_type, void *event)
34 {
35    Elocation_Position *position;
36
37    position = event;
38    _print_position(position);
39    return ECORE_CALLBACK_DONE;
40 }
41 #endif
42
43 EAPI_MAIN int
44 elm_main(int argc, char *argv[])
45 {
46 #ifdef ELM_ELOCATION
47    Elocation_Address *address;
48    Elocation_Position *position;
49 #endif
50
51    /* The program will proceed only if Ewebkit library is available. */
52    if (elm_need_elocation() == EINA_FALSE)
53      return -1;
54
55    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
56
57    win = elm_win_util_standard_add("elocation", "Elocation example");
58    elm_win_autodel_set(win, EINA_TRUE);
59
60    label = elm_label_add(win);
61    elm_label_line_wrap_set(label, ELM_WRAP_CHAR);
62    elm_object_text_set(label, "Getting location ...");
63    evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
64    evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
65    elm_label_slide_mode_set(label, ELM_LABEL_SLIDE_MODE_ALWAYS);
66    evas_object_resize(label, 600, 480);
67    evas_object_show(label);
68
69 #ifdef ELM_ELOCATION
70    address = elocation_address_new();
71    position = elocation_position_new();
72
73    ecore_event_handler_add(ELOCATION_EVENT_POSITION, _position_changed, NULL);
74
75    elocation_position_get(position);
76    _print_position(position);
77 #endif
78
79    evas_object_resize(win, 600, 480);
80    evas_object_show(win);
81
82    elm_run();
83
84 #ifdef ELM_ELOCATION
85    elocation_position_free(position);
86    elocation_address_free(address);
87 #endif
88
89    return 0;
90 }
91 ELM_MAIN()