stefan pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=a80b88c0ea76017195d6f6db07b35717915380a1

commit a80b88c0ea76017195d6f6db07b35717915380a1
Author: Stefan Schmidt <[email protected]>
Date:   Tue Oct 28 13:00:11 2014 +0100

    elocation: Add example for using the elocation API
    
    Basic example to show API usage.
---
 configure.ac                       |   1 +
 src/Makefile.am                    |   1 +
 src/examples/elocation/Makefile.am |  51 +++++++++++
 src/examples/elocation/elocation.c | 169 +++++++++++++++++++++++++++++++++++++
 4 files changed, 222 insertions(+)

diff --git a/configure.ac b/configure.ac
index 8b03024..be61443 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4467,6 +4467,7 @@ src/examples/emotion/Makefile
 src/examples/ethumb_client/Makefile
 src/examples/elua/Makefile
 src/examples/eolian_cxx/Makefile
+src/examples/elocation/Makefile
 src/lib/eina/eina_config.h
 src/lib/ecore_x/ecore_x_version.h
 src/lib/efl/Efl_Config.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 72830d5..57b56b7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -107,6 +107,7 @@ examples/eldbus \
 examples/ephysics \
 examples/edje \
 examples/emotion \
+examples/elocation \
 examples/ethumb_client
 
 if HAVE_ELUA
diff --git a/src/examples/elocation/Makefile.am 
b/src/examples/elocation/Makefile.am
new file mode 100644
index 0000000..3c843f8
--- /dev/null
+++ b/src/examples/elocation/Makefile.am
@@ -0,0 +1,51 @@
+MAINTAINERCLEANFILES = Makefile.in
+
+AM_CPPFLAGS = \
+-I$(top_builddir)/src/lib/efl \
+-I$(top_srcdir)/src/lib/eina \
+-I$(top_srcdir)/src/lib/eo \
+-I$(top_srcdir)/src/lib/ecore \
+-I$(top_srcdir)/src/lib/eldbus \
+-I$(top_srcdir)/src/lib/elocation \
+-I$(top_builddir)/src/lib/eina \
+-I$(top_builddir)/src/lib/eo \
+-I$(top_builddir)/src/lib/ecore \
+-I$(top_builddir)/src/lib/eldbus \
+-I$(top_builddir)/src/lib/elocation
+
+EXTRA_PROGRAMS = \
+elocation
+
+elocation_SOURCES = elocation.c
+elocation_LDADD = \
+$(top_builddir)/src/lib/elocation/libelocation.la \
+$(top_builddir)/src/lib/eo/libeo.la \
+$(top_builddir)/src/lib/ecore/libecore.la \
+$(top_builddir)/src/lib/eldbus/libeldbus.la \
+$(top_builddir)/src/lib/eina/libeina.la \
+@ELOCATION_LDFLAGS@
+
+SRCS = \
+elocation.c
+
+DATA_FILES = Makefile.examples
+
+EXTRA_DIST = $(DATA_FILES)
+
+examples: $(EXTRA_PROGRAMS)
+
+clean-local:
+       rm -f $(EXTRA_PROGRAMS)
+
+install-examples:
+       mkdir -p $(datadir)/elocation/examples
+       cd $(srcdir) && $(install_sh_DATA) -c $(SRCS) $(DATA_FILES) 
$(datadir)/elocation/examples
+
+uninstall-local:
+       for f in $(SRCS) $(DATA_FILES); do \
+         rm -f $(datadir)/elocation/examples/$$f ; \
+       done
+
+if ALWAYS_BUILD_EXAMPLES
+noinst_PROGRAMS = $(EXTRA_PROGRAMS)
+endif
diff --git a/src/examples/elocation/elocation.c 
b/src/examples/elocation/elocation.c
new file mode 100644
index 0000000..3006844
--- /dev/null
+++ b/src/examples/elocation/elocation.c
@@ -0,0 +1,169 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+
+#include <Ecore.h>
+#include <Elocation.h>
+
+/* A set of callbacks to react on incoming elocation events. They are standard
+ * ecore events and we register callbacks based on these events in the main
+ * function.
+ */
+static Eina_Bool
+status_changed(void *data, int ev_type, void *event)
+{
+   int *status = event;
+
+   printf("Status changed to: %i\n", *status);
+   printf("\n");
+
+   return ECORE_CALLBACK_DONE;
+}
+
+static Eina_Bool
+rgeocode_arrived(void *data, int ev_type, void *event)
+{
+   Elocation_Address *address;
+
+   address = event;
+   printf("Geocode reply:\n");
+   printf("Country: %s\n", address->country);
+   printf("Countrycode: %s\n", address->countrycode);
+   printf("Locality: %s\n", address->locality);
+   printf("Postalcode: %s\n", address->postalcode);
+   printf("Region: %s\n", address->region);
+   printf("Timezone: %s\n", address->timezone);
+   printf("Accuracy level: %i\n", address->accur->level);
+   printf("Accuracy horizontal: %f\n", address->accur->horizontal);
+   printf("Accuracy vertical: %f\n", address->accur->vertical);
+   printf("\n");
+
+   return ECORE_CALLBACK_DONE;
+}
+
+static Eina_Bool
+geocode_arrived(void *data, int ev_type, void *event)
+{
+   Elocation_Position *position;
+
+   position = event;
+   printf("Reverse geocode reply:\n");
+   printf("Latitude:\t %f\n", position->latitude);
+   printf("Longitude:\t %f\n", position->longitude);
+   printf("Altitude:\t %f\n", position->altitude);
+   printf("Accuracy level: %i\n", position->accur->level);
+   printf("Accuracy horizontal: %f\n", position->accur->horizontal);
+   printf("Accuracy vertical: %f\n", position->accur->vertical);
+   printf("\n");
+
+   return ECORE_CALLBACK_DONE;
+}
+
+static Eina_Bool
+address_changed(void *data, int ev_type, void *event)
+{
+   Elocation_Address *address;
+
+   address = event;
+   printf("Address update with data from timestamp: %i\n", address->timestamp);
+   printf("Country: %s\n", address->country);
+   printf("Countrycode: %s\n", address->countrycode);
+   printf("Locality: %s\n", address->locality);
+   printf("Postalcode: %s\n", address->postalcode);
+   printf("Region: %s\n", address->region);
+   printf("Timezone: %s\n", address->timezone);
+   printf("Accuracy level: %i\n", address->accur->level);
+   printf("Accuracy horizontal: %f\n", address->accur->horizontal);
+   printf("Accuracy vertical: %f\n", address->accur->vertical);
+   printf("\n");
+
+   return ECORE_CALLBACK_DONE;
+}
+
+static Eina_Bool
+position_changed(void *data, int ev_type, void *event)
+{
+   Elocation_Position *position;
+
+   position = event;
+   printf("GeoClue position reply with data from timestamp %i\n", 
position->timestamp);
+   printf("Latitude:\t %f\n", position->latitude);
+   printf("Longitude:\t %f\n", position->longitude);
+   printf("Altitude:\t %f\n", position->altitude);
+   printf("Accuracy level: %i\n", position->accur->level);
+   printf("Accuracy horizontal: %f\n", position->accur->horizontal);
+   printf("Accuracy vertical: %f\n", position->accur->vertical);
+   printf("\n");
+
+   return ECORE_CALLBACK_DONE;
+}
+
+int
+main(void)
+{
+   Elocation_Address *address, *addr_geocode;
+   Elocation_Position *position, *pos_geocode;
+   int status;
+
+   /* Init the needed efl subsystems so we can safely use them */
+   ecore_init();
+   eldbus_init();
+   elocation_init();
+
+   /* Create an address and positon object that we use for all our operations.
+    * Needs to be freed manually with elocation_*_free when we now longer use
+    * them */
+   address = elocation_address_new();
+   position = elocation_position_new();
+
+   /* Register callback so we get updates later on */
+   ecore_event_handler_add(ELOCATION_EVENT_STATUS, status_changed, NULL);
+   ecore_event_handler_add(ELOCATION_EVENT_POSITION, position_changed, NULL);
+   ecore_event_handler_add(ELOCATION_EVENT_ADDRESS, address_changed, NULL);
+   ecore_event_handler_add(ELOCATION_EVENT_GEOCODE, geocode_arrived, NULL);
+   ecore_event_handler_add(ELOCATION_EVENT_REVERSEGEOCODE, rgeocode_arrived, 
NULL);
+
+   /* To the initial request for status address and position. This fills in the
+    * objects with the data from GeoClue */
+   elocation_status_get(&status);
+   elocation_position_get(position);
+   elocation_address_get(address);
+
+   /* Another set of address and position object. This time for demonstrating
+    * the GeoCode functionalities */
+   addr_geocode = elocation_address_new();
+   pos_geocode = elocation_position_new();
+
+   /* The Freeform API could use any string to transform it into position
+    * coordinates. How good that works depends on the used GeoClue provider */
+   elocation_freeform_address_to_position("London", pos_geocode);
+
+   /* Some demo values to show the position to address conversion */
+   pos_geocode->latitude = 51.7522;
+   pos_geocode->longitude = -1.25596;
+   pos_geocode->accur->level = 3;
+   elocation_position_to_address(pos_geocode, addr_geocode);
+
+   /* And now from address to position */
+   addr_geocode->locality = "Cambridge";
+   addr_geocode->countrycode = "UK";
+   elocation_address_to_position(addr_geocode, pos_geocode);
+
+   /* Enter the mainloop now that we are setup with initial data and waiting 
for
+    * events. */
+   ecore_main_loop_begin();
+
+   /* Cleanup allocated memory now that we shut down */
+   elocation_address_free(addr_geocode);
+   elocation_position_free(pos_geocode);
+   elocation_address_free(address);
+   elocation_position_free(position);
+
+   /* Make sure we also shut down the initialized subsystems */
+   elocation_shutdown();
+   eldbus_shutdown();
+   ecore_shutdown();
+   return 0;
+}

-- 


Reply via email to