location_example_01.c
//Compile with:
//gcc -o location_example_01 location_example_01.c -g `pkg-config --cflags --libs elementary elocation`
#ifndef EFL_BETA_API_SUPPORT
# define EFL_BETA_API_SUPPORT
#endif
#include <Elementary.h>
#ifdef ELM_ELOCATION
#include <Elocation.h>
#endif
static Evas_Object *pos_label, *addr_label, *box, *win;
#ifdef ELM_ELOCATION
static void
_print_position(Elocation_Position *position)
{
char buffer[1024];
if (!position) return;
snprintf(buffer, sizeof(buffer),
"<b>### Position Detail ###</b><br/>"
"<b>GeoClue position reply with data from timestamp</b> %i<br/>"
"<b>Latitude:</b> %f<br/>"
"<b>Longitude:</b> %f<br/>"
"<b>Altitude:</b> %f<br/>"
"<b>Accuracy level:</b> %i<br/>"
"<b>Accuracy horizontal:</b> %f<br/>"
"<b>Accuracy vertical:</b> %f",
position->timestamp, position->latitude, position->longitude,
position->altitude, position->accur->level,
position->accur->horizontal, position->accur->vertical);
elm_object_text_set(pos_label, buffer);
}
static void
_print_address(Elocation_Address *address)
{
char buffer[1024];
if (!address) return;
snprintf(buffer, sizeof(buffer),
"<b>### Address Detail ###</b><br/>"
"<b>Address update with data from timestamp:</b> %i<br/>"
"<b>Country:</b> %s<br/>"
"<b>Countrycode:</b> %s<br/>"
"<b>Locality:</b> %s<br/>"
"<b>Postalcode:</b> %s<br/>"
"<b>Region:</b> %s<br/>"
"<b>Timezone:</b> %s<br/>"
"<b>Accuracy level:</b> %i<br/>"
"<b>Accuracy horizontal:</b> %f<br/>"
"<b>Accuracy vertical:</b> %f",
address->timestamp, address->country, address->countrycode,
address->locality, address->postalcode, address->region,
address->timezone, address->accur->level, address->accur->horizontal,
address->accur->vertical);
elm_object_text_set(addr_label, buffer);
}
static Eina_Bool
_position_changed(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *event)
{
Elocation_Position *position;
position = event;
_print_position(position);
}
static Eina_Bool
_address_changed(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *event)
{
address = event;
_print_address(address);
}
#endif
EAPI_MAIN int
elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
{
#ifdef ELM_ELOCATION
Elocation_Position *position;
#endif
/* The program will proceed only if Ewebkit library is available. */
if (elm_need_elocation() == EINA_FALSE)
return -1;
win = elm_win_util_standard_add("elocation", "Elocation example");
box = elm_box_add(win);
evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
pos_label = elm_label_add(box);
elm_label_line_wrap_set(pos_label, ELM_WRAP_CHAR);
elm_object_text_set(pos_label, "Getting location ...");
evas_object_size_hint_weight_set(pos_label, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(pos_label, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_label_slide_mode_set(pos_label, ELM_LABEL_SLIDE_MODE_ALWAYS);
elm_box_pack_end(box, pos_label);
evas_object_show(pos_label);
elm_box_padding_set(box, 0, 50);
addr_label = elm_label_add(box);
elm_label_line_wrap_set(addr_label, ELM_WRAP_CHAR);
elm_object_text_set(addr_label, "Getting location ...");
evas_object_size_hint_weight_set(addr_label, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(addr_label, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_label_slide_mode_set(addr_label, ELM_LABEL_SLIDE_MODE_ALWAYS);
elm_box_pack_end(box, addr_label);
evas_object_show(addr_label);
#ifdef ELM_ELOCATION
address = elocation_address_new();
position = elocation_position_new();
_print_position(position);
_print_address(address);
#endif
evas_object_resize(win, 600, 480);
#ifdef ELM_ELOCATION
#endif
return 0;
}
ELM_POLICY_QUIT_LAST_WINDOW_CLOSED
quit when the application's last window is closed
Definition: elm_general.h:248
elm_box_add
EAPI Evas_Object * elm_box_add(Evas_Object *parent)
Add a new box to the parent.
Definition: elm_box.c:366
elm_label_add
EAPI Evas_Object * elm_label_add(Evas_Object *parent)
Add a new label to the parent.
Definition: elm_label.c:413
EINA_UNUSED
#define EINA_UNUSED
Definition: eina_types.h:321
elocation_position_get
Eina_Bool elocation_position_get(Elocation_Position *position_shadow)
Get the current position information.
Definition: elocation.c:1128
_Elocation_Address
Definition: Elocation.h:166
EINA_FALSE
#define EINA_FALSE
Definition: eina_types.h:502
EVAS_HINT_EXPAND
#define EVAS_HINT_EXPAND
Use with evas_object_size_hint_weight_set(), evas_object_size_hint_weight_get(), evas_object_size_hin...
Definition: Evas_Common.h:292
ecore_event_handler_add
Ecore_Event_Handler * ecore_event_handler_add(int type, Ecore_Event_Handler_Cb func, const void *data)
Adds an event handler.
Definition: ecore_events.c:28
Evas_Object
Efl_Canvas_Object Evas_Object
Definition: Evas_Common.h:180
ECORE_CALLBACK_DONE
#define ECORE_CALLBACK_DONE
Return value to stop event handling.
Definition: Ecore_Common.h:156
elm_run
void elm_run(void)
Run Elementary's main loop.
Definition: elm_main.c:1385
elocation_position_new
Elocation_Position * elocation_position_new(void)
Create a new position object to operate on.
Definition: elocation.c:1150
ELM_MAIN
#define ELM_MAIN()
macro to be used after the elm_main() function
Definition: elm_general.h:528
_Elocation_Position
Definition: Elocation.h:186
elm_win_util_standard_add
Evas_Object * elm_win_util_standard_add(const char *name, const char *title)
Adds a window object with standard setup.
Definition: efl_ui_win.c:9199
elocation_position_free
void elocation_position_free(Elocation_Position *position_shadow)
Free an position object.
Definition: elocation.c:1180
Elocation.h
Elocation Library.
elocation_address_free
void elocation_address_free(Elocation_Address *address_shadow)
Free an address object.
Definition: elocation.c:1194
evas_object_show
void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1853
EVAS_HINT_FILL
#define EVAS_HINT_FILL
Use with evas_object_size_hint_align_set(), evas_object_size_hint_align_get(), evas_object_size_hint_...
Definition: Evas_Common.h:293
ELOCATION_EVENT_POSITION
EAPI int ELOCATION_EVENT_POSITION
Position changed.
Definition: elocation.c:44
EINA_TRUE
#define EINA_TRUE
Definition: eina_types.h:508
_Elocation_Address::timestamp
unsigned int timestamp
Timestamp of data read out in seconds since epoch.
Definition: Elocation.h:168
elm_policy_set
Eina_Bool elm_policy_set(unsigned int policy, int value)
Set a new policy's value (for a given policy group/identifier).
Definition: elm_main.c:1408
ELM_LABEL_SLIDE_MODE_ALWAYS
Slide always.
Definition: elm_label_eo.h:23
ELOCATION_EVENT_ADDRESS
EAPI int ELOCATION_EVENT_ADDRESS
Address changed.
Definition: elocation.c:45
Eina_Bool
unsigned char Eina_Bool
Definition: eina_types.h:496
ELM_WRAP_CHAR
Char wrap - wrap between characters.
Definition: elm_general.h:313
elm_win_resize_object_add
void elm_win_resize_object_add(Eo *obj, Evas_Object *subobj)
Add subobj as a resize object of window obj.
Definition: efl_ui_win.c:8899
elocation_address_new
Elocation_Address * elocation_address_new(void)
Create a new address object to operate on.
Definition: elocation.c:1165
elocation_address_get
Eina_Bool elocation_address_get(Elocation_Address *address_shadow)
Get the current address information.
Definition: elocation.c:1117
elm_win_autodel_set
void elm_win_autodel_set(Eo *obj, Eina_Bool autodel)
Set the window's autodel state.
Definition: efl_ui_win.c:6146
_Elocation_Position::timestamp
unsigned int timestamp
Timestamp of data read out in seconds since epoch.
Definition: Elocation.h:188
ELM_POLICY_QUIT
under which circumstances the application should quit automatically.
Definition: elm_general.h:227