diff options
author | Kim Kibum <kb0929.kim@samsung.com> | 2012-04-29 16:58:25 +0900 |
---|---|---|
committer | Kim Kibum <kb0929.kim@samsung.com> | 2012-04-29 16:58:25 +0900 |
commit | 140858710b2f71b790fb2212882c8aca3a76dc4a (patch) | |
tree | fba13188f667e6148c099392f05ac9a768ae174f | |
parent | 777cf1aec98857904b0034338ac6883bfae67044 (diff) | |
download | geocoder-140858710b2f71b790fb2212882c8aca3a76dc4a.tar.gz geocoder-140858710b2f71b790fb2212882c8aca3a76dc4a.tar.bz2 geocoder-140858710b2f71b790fb2212882c8aca3a76dc4a.zip |
upload tizen1.0 source
-rw-r--r-- | .gitignore | 26 | ||||
-rwxr-xr-x | CMakeLists.txt | 3 | ||||
-rw-r--r-- | capi-location-geocoder.pc.in | 2 | ||||
-rw-r--r-- | debian/changelog | 18 | ||||
-rw-r--r-- | debian/control | 6 | ||||
-rw-r--r--[-rwxr-xr-x] | include/geocoder.h | 66 | ||||
-rw-r--r-- | include/geocoder_private.h | 2 | ||||
-rw-r--r-- | packaging/capi-location-geocoder.spec | 11 | ||||
-rw-r--r-- | src/geocoder.c | 213 | ||||
-rw-r--r-- | test/geocoder_test.c | 36 |
10 files changed, 107 insertions, 276 deletions
diff --git a/.gitignore b/.gitignore deleted file mode 100644 index a6d8f19..0000000 --- a/.gitignore +++ /dev/null @@ -1,26 +0,0 @@ -CMakeCache.txt -*/CMakeFiles/* -*.cmake -CMakeFiles* -*.a -*.so -Testing -cmake.depends -cmake.check_depends -cmake.check_cache -core -core.* -gmon.out -install_manifest.txt -*~ -.kdev_include_paths -src.kdev4 -.cproject -.project -tet_captured -tet_lock -*.pc -Makefile -*-test -*-test_* -*tester.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 8fde9ce..de90ae5 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) SET(dependents "dlog location capi-base-common") +SET(pc_dependents "capi-base-common") INCLUDE(FindPkgConfig) pkg_check_modules(${fw_name} REQUIRED ${dependents}) @@ -50,7 +51,7 @@ INSTALL( ) SET(PC_NAME ${fw_name}) -SET(PC_REQUIRED ${dependents}) +SET(PC_REQUIRED ${pc_dependents}) SET(PC_LDFLAGS -l${fw_name}) SET(PC_CFLAGS -I\${includedir}/location) diff --git a/capi-location-geocoder.pc.in b/capi-location-geocoder.pc.in index d935ba8..150e613 100644 --- a/capi-location-geocoder.pc.in +++ b/capi-location-geocoder.pc.in @@ -11,5 +11,5 @@ Description: @PACKAGE_DESCRIPTION@ Version: @VERSION@ Requires: @PC_REQUIRED@ Libs: -L${libdir} @PC_LDFLAGS@ -Cflags: -I${includedir} @PC_CFLAGS@ +Cflags: -I${includedir} diff --git a/debian/changelog b/debian/changelog index 20bf21e..40dd8ef 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,21 @@ +capi-location-geocoder (0.1.0-14) unstable; urgency=low + + * Add the not found error code + + -- Kangho Hur <kangho.hur@samsung.com> Wed, 04 Apr 2012 13:26:23 +0900 + +capi-location-geocoder (0.1.0-12) unstable; urgency=low + + * Fix the callback issue + + -- Kangho Hur <kangho.hur@samsung.com> Wed, 28 Mar 2012 18:39:58 +0900 + +capi-location-geocoder (0.1.0-11) unstable; urgency=low + + * Add the result code for request(geocode/reverse geocode). Remove the sync function. + + -- Kangho Hur <kangho.hur@samsung.com> Mon, 26 Mar 2012 21:45:09 +0900 + capi-location-geocoder (0.1.0-9) unstable; urgency=low * Use 'static' to local function which is limited to the current source file. diff --git a/debian/control b/debian/control index dfed043..da095d9 100644 --- a/debian/control +++ b/debian/control @@ -2,17 +2,17 @@ Source: capi-location-geocoder Section: libs Priority: extra -Maintainer: Kangho Hur <kangho.hur@samsung.com> +Maintainer: Kangho Hur <kangho.hur@samsung.com>, Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com>, Hyuncheol Jung <hyuncheol.jung@samsung.com>, Genie Kim <daejins.kim@samsung.com> Build-Depends: debhelper (>= 5), dlog-dev, libslp-location-dev, capi-base-common-dev Package: capi-location-geocoder Architecture: any -Depends: ${shilbs:Depends}, ${misc:Depends} +Depends: ${shlibs:Depends}, ${misc:Depends} Description: A Geocoder library in Tizen Native API Package: capi-location-geocoder-dev Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, capi-location-geocoder (= ${Source-Version}), dlog-dev, libslp-location-dev, capi-base-common-dev +Depends: ${shlibs:Depends}, ${misc:Depends}, capi-location-geocoder (= ${Source-Version}) Description: A Geocoder library in Tizen Native API (DEV) Package: capi-location-geocoder-dbg diff --git a/include/geocoder.h b/include/geocoder.h index 504c907..701d828 100755..100644 --- a/include/geocoder.h +++ b/include/geocoder.h @@ -44,27 +44,29 @@ typedef enum GEOCODER_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ GEOCODER_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ GEOCODER_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + GEOCODER_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< Timeout error, no answer */ GEOCODER_ERROR_NETWORK_FAILED = TIZEN_ERROR_LOCATION_CLASS | 0x02, /**< Network unavailable*/ GEOCODER_ERROR_SERVICE_NOT_AVAILABLE = TIZEN_ERROR_LOCATION_CLASS | 0x03, /**< Service unavailable */ - GEOCODER_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< Timeout error, no answer */ + GEOCODER_ERROR_NOT_FOUND = TIZEN_ERROR_LOCATION_CLASS | 0x04, /**< Result not found */ } geocoder_error_e; /** * @brief Called once for each position information converted from the given address information. + * @param[in] result The result of request * @param[in] latitude The latitude [-90.0 ~ 90.0] (degrees) * @param[in] longitude The longitude [-180.0 ~ 180.0] (degrees) * @param[in] user_data The user data passed from the foreach function * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop - * @pre Either geocoder_foreach_positions_from_address() or geocoder_foreach_positions_from_address_sync() will invoke this callback. + * @pre geocoder_foreach_positions_from_address() will invoke this callback. * @see geocoder_foreach_positions_from_address() - * @see geocoder_foreach_positions_from_address_sync() */ -typedef bool(*geocoder_get_position_cb)(double latitude, double longitude, void *user_data); +typedef bool(*geocoder_get_position_cb)(geocoder_error_e result, double latitude, double longitude, void *user_data); /** * @brief Called when the address information has converted from position information. * @remarks You should not free all string values. + * @param[in] result The result of request * @param[in] building_number The building number * @param[in] postal_code The postal delivery code * @param[in] street The full street name @@ -76,7 +78,7 @@ typedef bool(*geocoder_get_position_cb)(double latitude, double longitude, void * @pre geocoder_get_address_from_position() will invoke this callback. * @see geocoder_get_address_from_position() */ -typedef void (*geocoder_get_address_cb)(const char *building_number, const char *postal_code, const char *street, const char *city, const char *district, const char *state, const char *country_code, void *user_data); +typedef void (*geocoder_get_address_cb)(geocoder_error_e result, const char *building_number, const char *postal_code, const char *street, const char *city, const char *district, const char *state, const char *country_code, void *user_data); /** * @brief Creates a new geocoder handle. @@ -93,7 +95,6 @@ typedef void (*geocoder_get_address_cb)(const char *building_number, const char */ int geocoder_create(geocoder_h *geocoder); - /** * @brief Destroys the geocoder handle and releases all its resources. * @param [in] geocoder The geocoder handle to destroy @@ -119,39 +120,11 @@ int geocoder_destroy(geocoder_h geocoder); * @retval #GEOCODER_ERROR_SERVICE_NOT_AVAILABLE Service not available * @post This function invokes geocoder_get_address_cb(). * @see geocoder_get_address_cb() - * @see geocoder_get_address_from_position_sync() * @see geocoder_foreach_positions_from_address() - * @see geocoder_foreach_positions_from_address_sync() */ int geocoder_get_address_from_position(geocoder_h geocoder, double latitude, double longitude, geocoder_get_address_cb callback, void *user_data); /** - * @brief Gets the address for a given position. - * @details The function tries to get the data immediately. If the attempt is unsuccessful, a corresponding error code is returned. - * @remarks This function requires network access. \n All output values must be released with @c free() by you. - * @param[in] geocoder The geocoder handle - * @param[in] latitude The latitude [-90.0 ~ 90.0] (degrees) - * @param[in] longitude The longitude [-180.0 ~ 180.0] (degrees) - * @param[out] building_number The building number - * @param[out] postal_code The postal delivery code - * @param[out] street The full street name - * @param[out] city The city name - * @param[out] district The municipal district name - * @param[out] state The state or province region of a nation - * @param[out] country_code The country code - * @return 0 on success, otherwise a negative error value. - * @retval #GEOCODER_ERROR_NONE Successful - * @retval #GEOCODER_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #GEOCODER_ERROR_NETWORK_FAILED Network connection failed - * @retval #GEOCODER_ERROR_SERVICE_NOT_AVAILABLE Service not available - * @see geocoder_get_address_from_position() - * @see geocoder_foreach_positions_from_address() - * @see geocoder_foreach_positions_from_address_sync() - */ -int geocoder_get_address_from_position_sync(geocoder_h geocoder, double latitude, double longitude, char **building_number, char **postal_code, char **street, char **city, char **district, char **state, char **country_code); - - -/** * @brief Gets the positions for a given address, asynchronously. * @details This function gets positions for a given free-formed address string. * @remarks This function requires network access. @@ -166,35 +139,10 @@ int geocoder_get_address_from_position_sync(geocoder_h geocoder, double latitude * @retval #GEOCODER_ERROR_SERVICE_NOT_AVAILABLE Service not available * @post It invokes geocoder_get_position_cb() to get changes in position. * @see geocoder_get_position_cb() - * @see geocoder_foreach_positions_from_address_sync() * @see geocoder_get_address_from_position() - * @see geocoder_get_address_from_position_sync() */ int geocoder_foreach_positions_from_address(geocoder_h geocoder, const char *address, geocoder_get_position_cb callback, void *user_data); - -/** - * @brief Gets the positions for a given address. - * @details This function gets the position for a given free-formed address string. - * @remarks This function requires network access. - * @param[in] geocoder The geocoder handle - * @param[in] address The free-formed address - * @param[in] callback The geocoder get positions callback function - * @param[in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #GEOCODER_ERROR_NONE Successful - * @retval #GEOCODER_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #GEOCODER_ERROR_NETWORK_FAILED Network connection failed - * @retval #GEOCODER_ERROR_SERVICE_NOT_AVAILABLE Service not available - * @retval #GEOCODER_ERROR_TIMED_OUT Timed out - * @post It invokes geocoder_get_position_cb() to get changes in position. - * @see geocoder_get_position_cb() - * @see geocoder_foreach_positions_from_address() - * @see geocoder_get_address_from_position() - * @see geocoder_get_address_from_position_sync() - */ -int geocoder_foreach_positions_from_address_sync(geocoder_h geocoder, const char *address, geocoder_get_position_cb callback, void *user_data); - /** * @} */ diff --git a/include/geocoder_private.h b/include/geocoder_private.h index 547996f..be31108 100644 --- a/include/geocoder_private.h +++ b/include/geocoder_private.h @@ -33,8 +33,6 @@ typedef enum { typedef struct _geocoder_s{ LocationObject* object; - const void* user_cb[_GEOCODER_CB_TYPE_NUM]; - void* user_data[_GEOCODER_CB_TYPE_NUM]; } geocoder_s; #ifdef __cplusplus diff --git a/packaging/capi-location-geocoder.spec b/packaging/capi-location-geocoder.spec index 63962e2..800a8fb 100644 --- a/packaging/capi-location-geocoder.spec +++ b/packaging/capi-location-geocoder.spec @@ -1,7 +1,7 @@ Name: capi-location-geocoder Summary: A Geocoder library in Tizen Native API -Version: 0.1.0 -Release: 1 +Version: 0.1.0 +Release: 14 Group: TO_BE/FILLED_IN License: Apache-2.0 Source0: %{name}-%{version}.tar.gz @@ -29,9 +29,8 @@ Requires: %{name} = %{version}-%{release} %build -FULLVER=%{version} -MAJORVER=`echo ${FULLVER} | cut -d '.' -f 1` -cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=${FULLVER} -DMAJORVER=${MAJORVER} +MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` +cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} make %{?jobs:-j%jobs} @@ -51,5 +50,3 @@ rm -rf %{buildroot} %files devel %{_includedir}/location/geocoder.h %{_libdir}/pkgconfig/*.pc - - diff --git a/src/geocoder.c b/src/geocoder.c index 95b43c5..cfcaa6c 100644 --- a/src/geocoder.c +++ b/src/geocoder.c @@ -39,6 +39,16 @@ * Internal Implementation */ +typedef struct { + void *data; + geocoder_get_address_cb callback; +}__addr_callback_data; + +typedef struct { + void *data; + geocoder_get_position_cb callback; +}__pos_callback_data; + static int __convert_error_code(int code, char* func_name) { int ret; @@ -58,6 +68,10 @@ static int __convert_error_code(int code, char* func_name) ret = GEOCODER_ERROR_INVALID_PARAMETER; msg = "GEOCODER_ERROR_INVALID_PARAMETER"; break; + case LOCATION_ERROR_NOT_FOUND: + ret = GEOCODER_ERROR_NOT_FOUND; + msg = "GEOCODER_ERROR_NOT_FOUND"; + break; case LOCATION_ERROR_NOT_ALLOWED: case LOCATION_ERROR_NOT_AVAILABLE: case LOCATION_ERROR_CONFIGURATION: @@ -72,53 +86,52 @@ static int __convert_error_code(int code, char* func_name) static void __cb_address_from_position (LocationError error, LocationAddress *addr, LocationAccuracy *acc, gpointer userdata) { - geocoder_s * handle = (geocoder_s*)userdata; - if(handle->user_cb[_GEOCODER_CB_ADDRESS_FROM_POSITION]) + __addr_callback_data * callback = (__addr_callback_data*)userdata; + if( callback == NULL || callback->callback == NULL) { - if(error != LOCATION_ERROR_NONE || addr == NULL) - { - __convert_error_code(error,(char*)__FUNCTION__); - ((geocoder_get_address_cb)handle->user_cb[_GEOCODER_CB_ADDRESS_FROM_POSITION])(NULL, NULL, NULL, NULL, NULL, NULL, NULL, handle->user_data[_GEOCODER_CB_ADDRESS_FROM_POSITION]); - } - else - { - LOGI("[%s] Address - building number: %s, postal code: %s, street: %s, city: %s, district: %s, state: %s, country code: %s", __FUNCTION__ , addr->building_number, addr->postal_code, addr->street, addr->city, addr->district, addr->state, addr->country_code); - ((geocoder_get_address_cb)handle->user_cb[_GEOCODER_CB_ADDRESS_FROM_POSITION])(addr->building_number, addr->postal_code, addr->street, addr->city, addr->district, addr->state, addr->country_code, handle->user_data[_GEOCODER_CB_ADDRESS_FROM_POSITION]); - } + LOGI("[%s] callback is NULL )",__FUNCTION__); + return ; + } + + if(error != LOCATION_ERROR_NONE || addr == NULL) + { + callback->callback(__convert_error_code(error,(char*)__FUNCTION__), NULL, NULL, NULL, NULL, NULL, NULL, NULL, callback->data); } else { - LOGI("[%s] callback is NULL )",__FUNCTION__); + LOGI("[%s] Address - building number: %s, postal code: %s, street: %s, city: %s, district: %s, state: %s, country code: %s", __FUNCTION__ , addr->building_number, addr->postal_code, addr->street, addr->city, addr->district, addr->state, addr->country_code); + callback->callback(GEOCODER_ERROR_NONE, addr->building_number, addr->postal_code, addr->street, addr->city, addr->district, addr->state, addr->country_code, callback->data); } + free(callback); } static void __cb_position_from_address (LocationError error, GList *position_list, GList *accuracy_list, gpointer userdata) { - geocoder_s * handle = (geocoder_s*)userdata; - if(handle->user_cb[_GEOCODER_CB_POSITION_FROM_ADDRESS]) + __pos_callback_data * callback = (__pos_callback_data*)userdata; + if( callback == NULL || callback->callback == NULL) { - if(error != LOCATION_ERROR_NONE || position_list == NULL || position_list->data ==NULL || accuracy_list==NULL ) - { - __convert_error_code(error,(char*)__FUNCTION__); - } - else + LOGI("[%s] callback is NULL )",__FUNCTION__); + return ; + } + + if(error != LOCATION_ERROR_NONE || position_list == NULL || position_list->data ==NULL || accuracy_list==NULL ) + { + callback->callback(__convert_error_code(error,(char*)__FUNCTION__), 0, 0, callback->data); + } + else + { + while(position_list) { - while(position_list) + LocationPosition *pos = position_list->data; + if ( callback->callback(GEOCODER_ERROR_NONE, pos->latitude, pos->longitude, callback->data) != TRUE ) { - LocationPosition *pos = position_list->data; - if ( ((geocoder_get_position_cb)handle->user_cb[_GEOCODER_CB_POSITION_FROM_ADDRESS])(pos->latitude, pos->longitude, handle->user_data[_GEOCODER_CB_POSITION_FROM_ADDRESS]) != TRUE ) - { - LOGI("[%s] User quit the loop ", __FUNCTION__); - break; - } - position_list = g_list_next(position_list); + LOGI("[%s] User quit the loop ", __FUNCTION__); + break; } + position_list = g_list_next(position_list); } } - else - { - LOGI("[%s] callback is NULL )",__FUNCTION__); - } + free(callback); } /* @@ -180,94 +193,25 @@ int geocoder_get_address_from_position(geocoder_h geocoder, double latitude, dou LocationPosition *pos = NULL; pos = location_position_new (0, latitude, longitude, 0, LOCATION_STATUS_2D_FIX); - handle->user_cb[_GEOCODER_CB_ADDRESS_FROM_POSITION] = callback; - handle->user_data[_GEOCODER_CB_ADDRESS_FROM_POSITION] = user_data; - - ret = location_get_address_from_position_async(handle->object, pos, __cb_address_from_position, handle); - if( ret != LOCATION_ERROR_NONE) + __addr_callback_data * calldata = (__addr_callback_data *)malloc(sizeof(__addr_callback_data)); + if( calldata == NULL) { - return __convert_error_code(ret,(char*)__FUNCTION__); + LOGE("[%s] GEOCODER_ERROR_OUT_OF_MEMORY(0x%08x) : fail to create callback data", __FUNCTION__, GEOCODER_ERROR_OUT_OF_MEMORY); + return GEOCODER_ERROR_OUT_OF_MEMORY; } - location_position_free(pos); - return GEOCODER_ERROR_NONE; -} - -int geocoder_get_address_from_position_sync(geocoder_h geocoder, double latitude, double longitude, char **building_number, char **postal_code, char **street, char **city, char **district, char **state, char **country_code) -{ - GEOCODER_NULL_ARG_CHECK(geocoder); - GEOCODER_CHECK_CONDITION(latitude>=-90 && latitude<=90 ,GEOCODER_ERROR_INVALID_PARAMETER,"GEOCODER_ERROR_INVALID_PARAMETER"); - GEOCODER_CHECK_CONDITION(longitude>=-180 && longitude<=180,GEOCODER_ERROR_INVALID_PARAMETER,"GEOCODER_ERROR_INVALID_PARAMETER"); + calldata->callback = callback; + calldata->data = user_data; - geocoder_s *handle = (geocoder_s*)geocoder; - int ret; - LocationAddress *addr = NULL; - LocationPosition *pos = NULL; - LocationAccuracy *acc = NULL; - - pos = location_position_new (0, latitude, longitude, 0, LOCATION_STATUS_2D_FIX); - ret = location_get_address_from_position(handle->object, pos, &addr, &acc); + ret = location_get_address_from_position_async(handle->object, pos, __cb_address_from_position, calldata); + location_position_free(pos); if( ret != LOCATION_ERROR_NONE) { + free(calldata); return __convert_error_code(ret,(char*)__FUNCTION__); } - - if(building_number) - { - *building_number = NULL; - if(addr->building_number) - *building_number = strdup(addr->building_number); - } - - if(postal_code) - { - *postal_code = NULL; - if(addr->postal_code) - *postal_code = strdup(addr->postal_code); - } - - if(street) - { - *street = NULL; - if(addr->street) - *street = strdup(addr->street); - } - - if(city) - { - *city = NULL; - if(addr->city) - *city = strdup(addr->city); - } - - if(state) - { - *state = NULL; - if(addr->state) - *state = strdup(addr->state); - } - - if(district) - { - *district = NULL; - if(addr->district) - *district = strdup(addr->district); - } - - if(country_code) - { - *country_code = NULL; - if(addr->country_code) - *country_code = strdup(addr->country_code); - } - - location_address_free(addr); - location_position_free(pos); - location_accuracy_free(acc); return GEOCODER_ERROR_NONE; } - - int geocoder_foreach_positions_from_address(geocoder_h geocoder,const char* address, geocoder_get_position_cb callback, void *user_data) { GEOCODER_NULL_ARG_CHECK(geocoder); @@ -276,53 +220,22 @@ int geocoder_foreach_positions_from_address(geocoder_h geocoder,const char* add geocoder_s *handle = (geocoder_s*)geocoder; char* addr_str = g_strdup(address); - handle->user_cb[_GEOCODER_CB_POSITION_FROM_ADDRESS] = callback; - handle->user_data[_GEOCODER_CB_POSITION_FROM_ADDRESS] = user_data; - int ret; - ret = location_get_position_from_freeformed_address_async(handle->object, addr_str,__cb_position_from_address, handle); - if( ret != LOCATION_ERROR_NONE) + __pos_callback_data * calldata = (__pos_callback_data *)malloc(sizeof(__pos_callback_data)); + if( calldata == NULL) { - g_free(addr_str); - return __convert_error_code(ret,(char*)__FUNCTION__); + LOGE("[%s] GEOCODER_ERROR_OUT_OF_MEMORY(0x%08x) : fail to create callback data", __FUNCTION__, GEOCODER_ERROR_OUT_OF_MEMORY); + return GEOCODER_ERROR_OUT_OF_MEMORY; } - return GEOCODER_ERROR_NONE; -} - -int geocoder_foreach_positions_from_address_sync(geocoder_h geocoder,const char* address, geocoder_get_position_cb callback, void *user_data) -{ - GEOCODER_NULL_ARG_CHECK(geocoder); - GEOCODER_NULL_ARG_CHECK(address); - GEOCODER_NULL_ARG_CHECK(callback); - geocoder_s *handle = (geocoder_s*)geocoder; - - int ret; - GList *pos_list = NULL; - GList *acc_list = NULL; - char* addr_str = g_strdup(address); - - - ret = location_get_position_from_freeformed_address(handle->object, addr_str, &pos_list, &acc_list); + calldata->callback = callback; + calldata->data = user_data; + int ret; + ret = location_get_position_from_freeformed_address_async(handle->object, addr_str,__cb_position_from_address, calldata); + g_free(addr_str); if( ret != LOCATION_ERROR_NONE) { - g_free(addr_str); return __convert_error_code(ret,(char*)__FUNCTION__); } - - while(pos_list) - { - LocationPosition *pos = pos_list->data; - if ( callback(pos->latitude, pos->longitude, user_data) != TRUE ) - { - LOGI("[%s] User quit the loop ", __FUNCTION__); - break; - } - pos_list = g_list_next(pos_list); - } - - g_free(addr_str); - g_list_free (pos_list); - g_list_free (acc_list); return GEOCODER_ERROR_NONE; } diff --git a/test/geocoder_test.c b/test/geocoder_test.c index 493ada0..f976896 100644 --- a/test/geocoder_test.c +++ b/test/geocoder_test.c @@ -22,7 +22,12 @@ geocoder_h geocoder; -static bool get_pos_cb(double latitude, double longitude, void *user_data) +static void get_addr_cb(geocoder_error_e result, const char *building_number, const char *postal_code, const char *street, const char *city, const char *district, const char *state, const char *country_code, void *user_data) +{ + printf("get_addr_cb() ===> building number: %s, postal code: %s, street: %s, city: %s, district: %s, state: %s, country code: %s\n", building_number,postal_code,street,city,district,state,country_code); +} + +static bool get_pos_cb(geocoder_error_e result, double latitude, double longitude, void *user_data) { printf ("get_pos_cb() ===> latitude : %g, longitude : %g\n",latitude, longitude); return true; @@ -40,29 +45,10 @@ int geocoder_test() } } - char *building_number; - char *postal_code; - char *street; - char *city; - char *district; - char *state; - char *country_code; - - ret = geocoder_get_address_from_position_sync(geocoder,37.258,127.056,&building_number,&postal_code,&street,&city,&district,&state,&country_code); + ret = geocoder_get_address_from_position(geocoder,37.258,127.056,get_addr_cb, NULL); if(ret != GEOCODER_ERROR_NONE) { - printf ("geocoder_get_address_from_position_sync return error : %d\n", ret); - } - else - { - printf("building number: %s, postal code: %s, street: %s, city: %s, district: %s, state: %s, country code: %s\n", building_number,postal_code,street,city,district,state,country_code); - free(building_number); - free(postal_code); - free(street); - free(city); - free(district); - free(state); - free(country_code); + printf ("geocoder_get_address_from_position return error : %d\n", ret); } return 1; } @@ -80,15 +66,11 @@ int reverse_geocoder_test() } char *address="suwon"; - ret = geocoder_foreach_positions_from_address_sync (geocoder,address, get_pos_cb, (void*)geocoder); + ret = geocoder_foreach_positions_from_address (geocoder,address, get_pos_cb, (void*)geocoder); if(ret != GEOCODER_ERROR_NONE) { printf ("geocoder_foreach_positions_from_address_sync return error : %d\n", ret); } - else - { - printf ("geocoder_foreach_positions_from_address_sync return OK : %d\n", ret); - } return 1; } |