From 52fd713be146584654a91731c954593922034cc9 Mon Sep 17 00:00:00 2001 From: Kevin Kreiser Date: Mon, 20 Jun 2016 16:36:36 -0400 Subject: [PATCH] Adds geocode support Change-Id: Id6a89248698d5aabbc02576d51d75fd6183f7676 --- CMakeLists.txt | 97 +++++++++++++++++-------- {inc => include}/mapzen_plugin.h | 45 ++++++++++++ {inc => include}/mapzen_plugin_internal.h | 0 packaging/maps-plugin-mapzen.spec | 47 ++++++++---- src/mapzen/mapzen_api.c | 14 ++-- src/mapzen/mapzen_geocode.c | 13 ++-- src/mapzen/mapzen_jsonparser.cpp | 114 +++++++++++++++++++++++++++++- src/mapzen/mapzen_jsonparser.hpp | 8 +++ src/mapzen/mapzen_queue.c | 72 +++++++++---------- src/mapzen/mapzen_revgeocode.c | 2 +- src/mapzen/mapzen_types.h | 12 ++-- src/mapzen_plugin.c | 65 +++++++++++++---- 12 files changed, 370 insertions(+), 119 deletions(-) rename {inc => include}/mapzen_plugin.h (68%) rename {inc => include}/mapzen_plugin_internal.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a906efc..2726d0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,26 +1,12 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -SET(pkg_name "maps-plugin-mapzen") -PROJECT(${pkg_name} C CXX) +SET(fw_name "maps-plugin-mapzen") +PROJECT(${fw_name} C CXX) SET(CMAKE_INSTALL_PREFIX /usr) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) -SET(LIBDIR ${LIBDIR}) # Dependencies -SET(dependents - glib-2.0 - gmodule-2.0 - libxml-2.0 - dlog - capi-maps-service - capi-network-connection - capi-appfw-app-manager - capi-appfw-application - evas - ecore-evas - elementary - vconf - ) +SET(dependents "glib-2.0 gmodule-2.0 dlog libcurl capi-network-connection capi-maps-service") INCLUDE(FindPkgConfig) pkg_check_modules(pkgs REQUIRED ${dependents}) @@ -36,8 +22,11 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fvisibility=hidden -fPIC -Wall -Werror") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -Wall -fPIC -std=c++11 -fvisibility=hidden") -SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpie ${EXTRA_CFLAGS} -Wall -g -fPIC -std=c++11 -fvisibility=hidden") + +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") +ENDIF("${ARCH}" STREQUAL "arm") ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") ADD_DEFINITIONS("-DEXPORT_API=__attribute__((visibility(\"default\")))") @@ -45,15 +34,30 @@ ADD_DEFINITIONS("-DTIZEN_DEBUG") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIBDIR}") -# Includes + +# Include files +# Maps Service Includes SET(INC_DIR - inc + include +) + +# Maps Service Implementation +SET(INTERNAL_INC_DIR + src +) + +# Mapzen Engine Implementation +SET(ENGINE_INC_DIR src/mapzen - external/rapidjson/include +) + +# External dependencies +SET(EXTERNAL_INC_DIR + external/rapidjson/include ) INCLUDE_DIRECTORIES( - ${INC_DIR} +${INC_DIR} ${INTERNAL_INC_DIR} ${ENGINE_INC_DIR} ${EXTERNAL_INC_DIR} ) #This file must be corrected @@ -62,25 +66,58 @@ INCLUDE_DIRECTORIES( SET(SRCS # Maps API src/mapzen_plugin.c + + # Mapzen Engine src/mapzen/mapzen_api.c src/mapzen/mapzen_geocode.c - src/mapzen/mapzen_jsonparser.cpp - src/mapzen/mapzen_place.c - src/mapzen/mapzen_queue.c - src/mapzen/mapzen_restcurl.c src/mapzen/mapzen_revgeocode.c src/mapzen/mapzen_route.cpp + src/mapzen/mapzen_place.c + src/mapzen/mapzen_restcurl.c + src/mapzen/mapzen_jsonparser.cpp + src/mapzen/mapzen_queue.c src/mapzen/mapzen_util.c ) -ADD_LIBRARY(${pkg_name} SHARED ${SRCS}) +ADD_LIBRARY(${fw_name} SHARED ${SRCS}) -SET_TARGET_PROPERTIES(${pkg_name} +SET_TARGET_PROPERTIES(${fw_name} PROPERTIES VERSION ${FULLVER} SOVERSION ${MAJORVER} CLEAN_DIRECT_OUTPUT 1 ) +TARGET_LINK_LIBRARIES(${fw_name} ${pkgs_LDFLAGS}) + +SET(PC_NAME ${fw_name}) +SET(PC_DESCRIPTION "Tizen mapzen plugin Library") +SET(PC_LDFLAGS -l${fw_name}) +SET(PC_INCLUDE /usr/include/maps) + +CONFIGURE_FILE( + ${fw_name}.pc.in + ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc + @ONLY +) + # Install -INSTALL(TARGETS ${pkg_name} DESTINATION ${LIBDIR}/maps/plugins) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig) +INSTALL(TARGETS ${fw_name} DESTINATION lib/maps/plugins) + +#INCLUDE(FindPkgConfig) +#pkg_check_modules(lib_pkgs REQUIRED +# capi-maps-service +#) + +SET(LIB_APP_ASSIST capi-maps-service) +INSTALL( + DIRECTORY ${INC_DIR}/ DESTINATION include/mapzen-plugin + FILES_MATCHING + PATTERN "*_internal.h" EXCLUDE + PATTERN "${INC_DIR}/mapzen_*.h" +) + +# Test Suite +#IF("${BINTYPE}" STREQUAL "eng") +#ENDIF("${BINTYPE}" STREQUAL "eng") diff --git a/inc/mapzen_plugin.h b/include/mapzen_plugin.h similarity index 68% rename from inc/mapzen_plugin.h rename to include/mapzen_plugin.h index acfb4d3..df24cfd 100644 --- a/inc/mapzen_plugin.h +++ b/include/mapzen_plugin.h @@ -48,6 +48,51 @@ typedef struct callback_place { int reqID; } callback_info_place; + +/* TODO: IMPLEMENT THESE FOR REAL */ + +int maps_plugin_multi_reverse_geocode(const maps_coordinates_list_h geocode_list, + const maps_preference_h preference, maps_service_multi_reverse_geocode_cb callback, + void *user_data, int *request_id); + +int maps_plugin_search_place_list(const maps_area_h boundary, const maps_place_filter_h filter, + maps_preference_h preference, maps_service_search_place_list_cb callback, void* user_data, int* request_id); + +int maps_plugin_get_place_details(const char* url, + maps_service_get_place_details_cb callback, void* user_data, int* request_id); + +int maps_plugin_create_map_view(maps_view_h hView, maps_plugin_map_view_ready_cb pCbFunc); + +int maps_plugin_destroy_map_view(maps_view_h hView); + +int maps_plugin_render_map(maps_view_h hView, + const maps_coordinates_h coordinates, double zoom_factor, double rotation_angle); + +int maps_plugin_move_center(maps_view_h hView, int delta_x, int delta_y); + +int maps_plugin_set_scalebar(maps_view_h hView, bool enable); + +int maps_plugin_get_scalebar(maps_view_h hView, bool *enabled); + +int maps_plugin_draw_map(maps_view_h hView, Evas* canvas, int x, int y, int w, int h); + +int maps_plugin_on_object(maps_view_h hView, const maps_view_object_h object, maps_view_object_operation_e operation); + +int maps_plugin_screen_to_geography(maps_view_h hView, int x, int y, maps_coordinates_h *mapsCoord); + +int maps_plugin_geography_to_screen(maps_view_h hView, const maps_coordinates_h mapsCoord, int* x, int* y); + +int maps_plugin_get_min_zoom_level(maps_view_h hView, int *min_zoom_level); + +int maps_plugin_get_max_zoom_level(maps_view_h hView, int *max_zoom_level); + +int maps_plugin_get_center(maps_view_h hView, maps_coordinates_h *center); + +/* ABOVE METHODS ARE THERE BUT RETURN MAPS_ERROR_NOT_SUPPORTED */ + + +int maps_plugin_init_module(maps_plugin_h *plugin, const char *module); + int maps_plugin_init(maps_plugin_h *plugin); int maps_plugin_shutdown(maps_plugin_h plugin); diff --git a/inc/mapzen_plugin_internal.h b/include/mapzen_plugin_internal.h similarity index 100% rename from inc/mapzen_plugin_internal.h rename to include/mapzen_plugin_internal.h diff --git a/packaging/maps-plugin-mapzen.spec b/packaging/maps-plugin-mapzen.spec index f0e38f0..65900b9 100644 --- a/packaging/maps-plugin-mapzen.spec +++ b/packaging/maps-plugin-mapzen.spec @@ -8,21 +8,17 @@ Source0: %{name}-%{version}.tar.gz Source1: deps.tar.gz ExclusiveArch: %ix86 x86_64 %arm aarch64 -BuildRequires: cmake -BuildRequires: pkgconfig(libxml-2.0) -BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(libcurl) -BuildRequires: pkgconfig(capi-maps-service) -BuildRequires: capi-maps-service-plugin-devel -BuildRequires: pkgconfig(capi-network-connection) -BuildRequires: pkgconfig(capi-appfw-app-manager) -BuildRequires: pkgconfig(capi-appfw-application) -BuildRequires: pkgconfig(capi-system-info) -BuildRequires: pkgconfig(elementary) -BuildRequires: pkgconfig(vconf) -BuildRequires: boost-devel -BuildRequires: capi-maps-service-devel -BuildRequires: elementary-devel +BuildRequires: cmake +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(gmodule-2.0) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(libcurl) +BuildRequires: pkgconfig(capi-network-connection) +BuildRequires: pkgconfig(capi-maps-service) +BuildRequires: capi-maps-service-plugin-devel +BuildRequires: pkgconfig(json-glib-1.0) +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig # Requires(post): /sbin/ldconfig @@ -79,4 +75,25 @@ cp LICENSE %{buildroot}/usr/share/license/%{name} %manifest maps-plugin-mapzen.manifest %defattr(-,root,root,-) %{_prefix}/lib/maps/plugins/libmaps-plugin-mapzen.so* +%{_prefix}/lib/pkgconfig/maps-plugin-mapzen.pc /usr/share/license/maps-plugin-mapzen + +%package devel +Summary: Tizen Mapzen Maps Plug-in Library (Development) +Group: Framework/maps +Requires: %{name} = %{version}-%{release} + +%description devel +This package provides Plugin APIs for Mapzen. (Development) + +%post devel +/sbin/ldconfig + +%postun devel +/sbin/ldconfig + +%files devel +%defattr(-,root,root,-) +%{_includedir}/mapzen-plugin/*.h +%{_prefix}/lib/pkgconfig/maps-plugin-mapzen.pc +%{_prefix}/lib/maps/plugins/libmaps-plugin-mapzen.so diff --git a/src/mapzen/mapzen_api.c b/src/mapzen/mapzen_api.c index 4eb72b5..26e709f 100644 --- a/src/mapzen/mapzen_api.c +++ b/src/mapzen/mapzen_api.c @@ -21,21 +21,21 @@ #include "mapzen_queue.h" #include "mapzen_debug.h" -EXPORT_API int mapzen_init() +int mapzen_init() { int ret = mapzen_init_queue(); return ret; } -EXPORT_API int mapzen_shutdown() +int mapzen_shutdown() { int ret = mapzen_deinit_queue(); return ret; } -EXPORT_API int mapzen_geocode(mapzen_geocode_req_s *req_details, mapzen_geocode_cb callback, int request_id, void *user_data) +int mapzen_geocode(mapzen_geocode_req_s *req_details, mapzen_geocode_cb callback, int request_id, void *user_data) { int ret = MAPZEN_ERROR_NONE; ret = start_geocode_service(req_details, callback, request_id, user_data); @@ -43,14 +43,14 @@ EXPORT_API int mapzen_geocode(mapzen_geocode_req_s *req_details, mapzen_geocode_ return ret; } -EXPORT_API int mapzen_cancel_request(int request_id) +int mapzen_cancel_request(int request_id) { int ret = remove_from_request_list(request_id); return ret; } -EXPORT_API int mapzen_reverse_geocode(mapzen_revgeocode_req_s *req_details, mapzen_reverse_geocode_cb callback, int request_id, void *user_data) +int mapzen_reverse_geocode(mapzen_revgeocode_req_s *req_details, mapzen_reverse_geocode_cb callback, int request_id, void *user_data) { int ret = MAPZEN_ERROR_NONE; ret = start_reversegeocode_service(req_details, callback, request_id, user_data); @@ -58,7 +58,7 @@ EXPORT_API int mapzen_reverse_geocode(mapzen_revgeocode_req_s *req_details, mapz return ret; } -EXPORT_API int mapzen_search_place(mapzen_search_req_s *req_details, mapzen_place_search_cb callback, int request_id, void *user_data) +int mapzen_search_place(mapzen_search_req_s *req_details, mapzen_place_search_cb callback, int request_id, void *user_data) { int ret = MAPZEN_ERROR_NONE; ret = start_places_service(req_details, callback, request_id, user_data); @@ -66,7 +66,7 @@ EXPORT_API int mapzen_search_place(mapzen_search_req_s *req_details, mapzen_plac return ret; } -EXPORT_API int mapzen_start_route(mapzen_route_req_s *req_details, mapzen_route_cb callback, int request_id, void *user_data) +int mapzen_start_route(mapzen_route_req_s *req_details, mapzen_route_cb callback, int request_id, void *user_data) { int ret = MAPZEN_ERROR_NONE; ret = start_route_service(req_details, callback, request_id, user_data); diff --git a/src/mapzen/mapzen_geocode.c b/src/mapzen/mapzen_geocode.c index c7719cf..799bf15 100644 --- a/src/mapzen/mapzen_geocode.c +++ b/src/mapzen/mapzen_geocode.c @@ -25,7 +25,7 @@ #include "mapzen_restcurl.h" #include "mapzen_util.h" -#define GEOCODE_URL "https://open.mapzenapi.com/geocoding/v1/address?key=%s&inFormat=kvp&outFormat=json" +#define GEOCODE_URL "https://search.mapzen.com/v1/search?api_key=%s" int query_geocode_within_bounds(gchar *maps_key, char *address, coords_s top_left, coords_s bottom_right, int num_results, gpointer user_data) { @@ -39,13 +39,14 @@ int query_geocode_within_bounds(gchar *maps_key, char *address, coords_s top_lef STRCPY(url, tmpStr); - snprintf(tmpStr, sizeof(tmpStr), "&boundingBox=%f,%f,%f,%f", top_left.latitude, top_left.longitude, bottom_right.latitude, bottom_right.longitude); + snprintf(tmpStr, sizeof(tmpStr), "&boundary.rect.min_lat=%f&boundary.rect.min_lon=%f&boundary.rect.max_lat=%f&boundary.rect.max_lon=%f", + top_left.latitude, top_left.longitude, bottom_right.latitude, bottom_right.longitude); STRCAT(url, tmpStr); - snprintf(tmpStr, sizeof(tmpStr), "&maxResults=%d", num_results); + snprintf(tmpStr, sizeof(tmpStr), "&size=%d", num_results); STRCAT(url, tmpStr); - snprintf(tmpStr, sizeof(tmpStr), "&location=%s", address); + snprintf(tmpStr, sizeof(tmpStr), "&layers=address&text=%s", address); STRCAT(url, tmpStr); add_handle(url, REQ_TYPE_GEOCODE, user_data); @@ -66,10 +67,10 @@ int query_geocode(gchar *maps_key, char *address, int num_results, gpointer user STRCPY(url, tmpStr); - snprintf(tmpStr, sizeof(tmpStr), "&maxResults=%d", num_results); + snprintf(tmpStr, sizeof(tmpStr), "&size=%d", num_results); STRCAT(url, tmpStr); - snprintf(tmpStr, sizeof(tmpStr), "&location=%s", address); + snprintf(tmpStr, sizeof(tmpStr), "&layers=address&text=%s", address); STRCAT(url, tmpStr); add_handle(url, REQ_TYPE_GEOCODE, user_data); diff --git a/src/mapzen/mapzen_jsonparser.cpp b/src/mapzen/mapzen_jsonparser.cpp index 34a847d..34cb807 100644 --- a/src/mapzen/mapzen_jsonparser.cpp +++ b/src/mapzen/mapzen_jsonparser.cpp @@ -17,7 +17,7 @@ #include #include -#include "rapidjson/rapidjson.h" +#include "rapidjson/document.h" #include "mapzen_jsonparser.hpp" #include "mapzen_queue.h" #include "mapzen_debug.h" @@ -26,6 +26,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #define ROUTE_UNIT_CONVERSION_MILE_TO_M(x) (1609.34 * (x)) #define ROUTE_UNIT_CONVERSION_MILE_TO_KM(x) (1.60934 * (x)) #define ROUTE_UNIT_CONVERSION_MILE_TO_FT(x) (5280 * (x)) @@ -120,16 +124,64 @@ static mapzen_error_e __convert_status(int status) return error; } +bool __get_string(const rapidjson::Value& obj, const char* key, char** value) +{ + //if we have the key and its not an empty value + rapidjson::Value::ConstMemberIterator itr = obj.FindMember(key); + if(itr != obj.MemberEnd() && itr->value.GetStringLength()){ + (*value) = (gchar *)g_malloc(itr->value.GetStringLength() + 1); + strncpy((*value), itr->value.GetString(), itr->value.GetStringLength()); + }//we had nothing + else + (*value) = NULL; + //is this something + return *value != NULL; +} + /************ GEOCODE ***************/ static void __parse_geocode_response(char *response, int size, int *status, GList **coordsList) { + MAP_DEBUG("Inside __parse_geocode_response.."); + + if (!response || !status || !coordsList) return; *coordsList = NULL; - //TODO: + //crack open that json + rapidjson::Document document; + document.Parse(std::string(response, size).c_str()); + rapidjson::Value::ConstMemberIterator features = document.FindMember("features"); + if(features != document.MemberEnd() && features->value.IsArray()) { + //for each feature + for (rapidjson::Value::ConstValueIterator f = features->value.Begin(); f != features->value.End(); ++f) { + //it has to have geometry + rapidjson::Value::ConstMemberIterator geom = f->FindMember("geometry"); + if(geom != f->MemberEnd()) { + //skip non-points + rapidjson::Value::ConstMemberIterator type = geom->value.FindMember("type"); + if(type == geom->value.MemberEnd() || strcmp(type->value.GetString(), "Point")) + continue; + //get actual points + rapidjson::Value::ConstMemberIterator coords = geom->value.FindMember("coordinates"); + if(coords == geom->value.MemberEnd() || !coords->value.IsArray() || coords->value.Size() != 2) + continue; + + coords_s *coord = (coords_s *)g_malloc0(sizeof(coords_s)); + if (coord != NULL) { + coord->latitude = coords->value[0].GetDouble(); + coord->longitude = coords->value[1].GetDouble(); + } + + if (*coordsList == NULL) + *coordsList = g_list_append(*coordsList, coord); + else + *coordsList = g_list_insert_before(*coordsList, NULL, coord); + } + } + } } /****************** REVERSE GEOCODE *********************/ @@ -140,7 +192,59 @@ static void __parse_revgeocode_response(char *response, int size, int *status, m *respAddr = NULL; - //TODO: + //crack open that json + rapidjson::Document document; + document.Parse(std::string(response, size).c_str()); + rapidjson::Value::ConstMemberIterator features = document.FindMember("features"); + if(features != document.MemberEnd() && features->value.IsArray()) { + //for each feature + for (rapidjson::Value::ConstValueIterator f = features->value.Begin(); f != features->value.End(); ++f) { + //it has to have geometry + rapidjson::Value::ConstMemberIterator geom = f->FindMember("geometry"); + if(geom != f->MemberEnd()) { + //skip non-points + rapidjson::Value::ConstMemberIterator type = geom->value.FindMember("type"); + if(type == geom->value.MemberEnd() || strcmp(type->value.GetString(), "Point")) + continue; + //get actual points + rapidjson::Value::ConstMemberIterator coords = geom->value.FindMember("coordinates"); + if(coords == geom->value.MemberEnd() || !coords->value.IsArray() || coords->value.Size() != 2) + continue; + maps_coordinates_s coord; + coord.longitude = coords->value[0].GetDouble(); + coord.latitude = coords->value[1].GetDouble(); + //NOTE: it seems as though the tizen maps plugin api assumes that reverse geocode results will + //actually be at the coordinates where you requested the reverse geocode. the mapzen api can return + //POIS which are some distance away from the location and currently this is not accounted for :o( + + //get out the address information + rapidjson::Value::ConstMemberIterator properties = f->FindMember("properties"); + if(properties != f->MemberEnd()) { + //fill this out as we go + *respAddr = (mapzen_address_resp_s *)g_malloc(sizeof(mapzen_address_resp_s)); + bool something = false; + something = __get_string(properties->value, "street", &(*respAddr)->street) || something; + something = __get_string(properties->value, "neighbourhood", &(*respAddr)->neighbourhood) || something; + something = __get_string(properties->value, "housenumber", &(*respAddr)->housenumber) || something; + something = __get_string(properties->value, "localadmin", &(*respAddr)->localadmin) || something; + something = __get_string(properties->value, "county", &(*respAddr)->county) || something; + something = __get_string(properties->value, "region", &(*respAddr)->region) || something; + something = __get_string(properties->value, "country", &(*respAddr)->country) || something; + something = __get_string(properties->value, "country_a", &(*respAddr)->country_a) || something; + something = __get_string(properties->value, "postalcode", &(*respAddr)->postalcode) || something; + //if everything was null thats pretty much unusable + //TODO: these are pretty weak criteria.. + if(!something) { + g_free(*respAddr); + (*respAddr) = NULL; + }//forget the rest, we have one with something in it + else + break; + } + } + } + + } } /**************** PLACE SEARCH ********************/ @@ -356,3 +460,7 @@ void post_curl_response(char *response, int size, mapzen_resp_type type, void *u } } } + +#ifdef __cplusplus +} +#endif diff --git a/src/mapzen/mapzen_jsonparser.hpp b/src/mapzen/mapzen_jsonparser.hpp index 9a766eb..7b356f0 100644 --- a/src/mapzen/mapzen_jsonparser.hpp +++ b/src/mapzen/mapzen_jsonparser.hpp @@ -19,6 +19,14 @@ #include "mapzen_server_private.h" +#ifdef __cplusplus +extern "C" { +#endif + void post_curl_response(char *response, int size, mapzen_resp_type type, void *user_data); +#ifdef __cplusplus +} +#endif + #endif /* _MAPZEN_JSONPARSER_H_ */ diff --git a/src/mapzen/mapzen_queue.c b/src/mapzen/mapzen_queue.c index e4b08c0..99a681d 100644 --- a/src/mapzen/mapzen_queue.c +++ b/src/mapzen/mapzen_queue.c @@ -15,7 +15,7 @@ */ #include -#include +#include #include "mapzen_queue.h" #include "mapzen_geocode.h" #include "mapzen_revgeocode.h" @@ -724,37 +724,37 @@ static void __free_revgeocode_response(void *ptr) MapzenRevGeocodeResponseData *revGeocodeData = (MapzenRevGeocodeResponseData *) (ptr); if (revGeocodeData) { if (revGeocodeData->addressDetails) { - if (revGeocodeData->addressDetails->street_add) { - g_free(revGeocodeData->addressDetails->street_add); - revGeocodeData->addressDetails->street_add = NULL; + if (revGeocodeData->addressDetails->street) { + g_free(revGeocodeData->addressDetails->street); + revGeocodeData->addressDetails->street = NULL; } if (revGeocodeData->addressDetails->neighbourhood) { g_free(revGeocodeData->addressDetails->neighbourhood); revGeocodeData->addressDetails->neighbourhood = NULL; } - if (revGeocodeData->addressDetails->city) { - g_free(revGeocodeData->addressDetails->city); - revGeocodeData->addressDetails->city = NULL; + if (revGeocodeData->addressDetails->localadmin) { + g_free(revGeocodeData->addressDetails->localadmin); + revGeocodeData->addressDetails->localadmin = NULL; } if (revGeocodeData->addressDetails->county) { g_free(revGeocodeData->addressDetails->county); revGeocodeData->addressDetails->county = NULL; } - if (revGeocodeData->addressDetails->state) { - g_free(revGeocodeData->addressDetails->state); - revGeocodeData->addressDetails->state = NULL; + if (revGeocodeData->addressDetails->region) { + g_free(revGeocodeData->addressDetails->region); + revGeocodeData->addressDetails->region = NULL; } if (revGeocodeData->addressDetails->country) { g_free(revGeocodeData->addressDetails->country); revGeocodeData->addressDetails->country = NULL; } - if (revGeocodeData->addressDetails->country_code) { - g_free(revGeocodeData->addressDetails->country_code); - revGeocodeData->addressDetails->country_code = NULL; + if (revGeocodeData->addressDetails->country_a) { + g_free(revGeocodeData->addressDetails->country_a); + revGeocodeData->addressDetails->country_a = NULL; } - if (revGeocodeData->addressDetails->postal_code) { - g_free(revGeocodeData->addressDetails->postal_code); - revGeocodeData->addressDetails->postal_code = NULL; + if (revGeocodeData->addressDetails->postalcode) { + g_free(revGeocodeData->addressDetails->postalcode); + revGeocodeData->addressDetails->postalcode = NULL; } g_free(revGeocodeData->addressDetails); @@ -779,41 +779,41 @@ static void __free_place_response(void *ptr) mapzen_place_resp_s *mapzen_place = (mapzen_place_resp_s *) place->data; if (mapzen_place->address) { - if (mapzen_place->address->street_add) { - g_free(mapzen_place->address->street_add); - mapzen_place->address->street_add = NULL; + if (mapzen_place->address->street) { + g_free(mapzen_place->address->street); + mapzen_place->address->street = NULL; } if (mapzen_place->address->neighbourhood) { g_free(mapzen_place->address->neighbourhood); mapzen_place->address->neighbourhood = NULL; } - if (mapzen_place->address->building_number) { - g_free(mapzen_place->address->building_number); - mapzen_place->address->building_number = NULL; + if (mapzen_place->address->housenumber) { + g_free(mapzen_place->address->housenumber); + mapzen_place->address->housenumber = NULL; } - if (mapzen_place->address->city) { - g_free(mapzen_place->address->city); - mapzen_place->address->city = NULL; + if (mapzen_place->address->localadmin) { + g_free(mapzen_place->address->localadmin); + mapzen_place->address->localadmin = NULL; } if (mapzen_place->address->county) { g_free(mapzen_place->address->county); mapzen_place->address->county = NULL; } - if (mapzen_place->address->state) { - g_free(mapzen_place->address->state); - mapzen_place->address->state = NULL; + if (mapzen_place->address->region) { + g_free(mapzen_place->address->region); + mapzen_place->address->region = NULL; } if (mapzen_place->address->country) { g_free(mapzen_place->address->country); mapzen_place->address->country = NULL; } - if (mapzen_place->address->country_code) { - g_free(mapzen_place->address->country_code); - mapzen_place->address->country_code = NULL; + if (mapzen_place->address->country_a) { + g_free(mapzen_place->address->country_a); + mapzen_place->address->country_a = NULL; } - if (mapzen_place->address->postal_code) { - g_free(mapzen_place->address->postal_code); - mapzen_place->address->postal_code = NULL; + if (mapzen_place->address->postalcode) { + g_free(mapzen_place->address->postalcode); + mapzen_place->address->postalcode = NULL; } g_free(mapzen_place->address); mapzen_place->address = NULL; @@ -919,10 +919,6 @@ static void __free_route_response(void *ptr) int mapzen_init_queue() { -#if !GLIB_CHECK_VERSION(2, 35, 0) - g_type_init(); /* Needed for using json in Emulator */ -#endif - pthread_mutex_init(&__requestLock, NULL); /* Queue initialize */ diff --git a/src/mapzen/mapzen_revgeocode.c b/src/mapzen/mapzen_revgeocode.c index ebe173c..24eba4a 100644 --- a/src/mapzen/mapzen_revgeocode.c +++ b/src/mapzen/mapzen_revgeocode.c @@ -25,7 +25,7 @@ #include "mapzen_restcurl.h" #include "mapzen_util.h" -#define REVERSE_GEOCODE_URL "https://search.mapzen.com/v1/reverse?size=1&point.lat=%f&point.lon=%f&api_key=%s" +#define REVERSE_GEOCODE_URL "https://search.mapzen.com/v1/reverse?size=10&layers=address,locality&point.lat=%f&point.lon=%f&api_key=%s" int query_revgeocode(gchar *maps_key, gdouble latitude, gdouble longitude, gpointer user_data) { diff --git a/src/mapzen/mapzen_types.h b/src/mapzen/mapzen_types.h index 356bf52..ddf1264 100644 --- a/src/mapzen/mapzen_types.h +++ b/src/mapzen/mapzen_types.h @@ -134,15 +134,15 @@ typedef struct { } mapzen_tiledata_req_s; typedef struct { - gchar *street_add; + gchar *street; gchar *neighbourhood; - gchar *building_number; - gchar *city; + gchar *housenumber; + gchar *localadmin; gchar *county; - gchar *state; + gchar *region; gchar *country; - gchar *country_code; - gchar *postal_code; + gchar *country_a; + gchar *postalcode; } mapzen_address_resp_s; typedef struct { diff --git a/src/mapzen_plugin.c b/src/mapzen_plugin.c index c00bf8b..a87258b 100644 --- a/src/mapzen_plugin.c +++ b/src/mapzen_plugin.c @@ -148,7 +148,40 @@ static bool __replace_space(char *place_name, char **modified_place_name) return false; } -EXPORT_API int maps_plugin_init(maps_plugin_h *plugin) + +/*MASSIVE TODO: + * + * THE TIZEN API REQUIRES A BUNCH MORE FUNCTIONS A LOT OF WHICH HAVE TO DO WITH MAP RENDERING + * TO BE ABLE TO LOAD THE LIBRARY IN A COMPATIBLE WAY. HERE WE STUB OUT THE METHODS BUT DO NO + * IMPLEMENTING JUST SO WE CAN TEST THE STUFF WE HAVE DONE... + */ + +EXPORT_API int maps_plugin_multi_reverse_geocode(const maps_coordinates_list_h geocode_list, + const maps_preference_h preference, maps_service_multi_reverse_geocode_cb callback, + void *user_data, int *request_id){return MAPS_ERROR_NOT_SUPPORTED ;} +EXPORT_API int maps_plugin_search_place_list(const maps_area_h boundary, const maps_place_filter_h filter, + maps_preference_h preference, maps_service_search_place_list_cb callback, void* user_data, int* request_id){return MAPS_ERROR_NOT_SUPPORTED ;} +EXPORT_API int maps_plugin_get_place_details(const char* url, + maps_service_get_place_details_cb callback, void* user_data, int* request_id){return MAPS_ERROR_NOT_SUPPORTED ;} +EXPORT_API int maps_plugin_create_map_view(maps_view_h hView, maps_plugin_map_view_ready_cb pCbFunc){return MAPS_ERROR_NOT_SUPPORTED ;} +EXPORT_API int maps_plugin_destroy_map_view(maps_view_h hView){return MAPS_ERROR_NOT_SUPPORTED ;} +EXPORT_API int maps_plugin_render_map(maps_view_h hView, + const maps_coordinates_h coordinates, double zoom_factor, double rotation_angle){return MAPS_ERROR_NOT_SUPPORTED ;} +EXPORT_API int maps_plugin_move_center(maps_view_h hView, int delta_x, int delta_y){return MAPS_ERROR_NOT_SUPPORTED ;} +EXPORT_API int maps_plugin_set_scalebar(maps_view_h hView, bool enable){return MAPS_ERROR_NOT_SUPPORTED ;} +EXPORT_API int maps_plugin_get_scalebar(maps_view_h hView, bool *enabled){return MAPS_ERROR_NOT_SUPPORTED ;} +EXPORT_API int maps_plugin_draw_map(maps_view_h hView, Evas* canvas, int x, int y, int w, int h){return MAPS_ERROR_NOT_SUPPORTED ;} +EXPORT_API int maps_plugin_on_object(maps_view_h hView, const maps_view_object_h object, maps_view_object_operation_e operation){return MAPS_ERROR_NOT_SUPPORTED ;} +EXPORT_API int maps_plugin_screen_to_geography(maps_view_h hView, int x, int y, maps_coordinates_h *mapsCoord){return MAPS_ERROR_NOT_SUPPORTED ;} +EXPORT_API int maps_plugin_geography_to_screen(maps_view_h hView, const maps_coordinates_h mapsCoord, int* x, int* y){return MAPS_ERROR_NOT_SUPPORTED ;} +EXPORT_API int maps_plugin_get_min_zoom_level(maps_view_h hView, int *min_zoom_level){return MAPS_ERROR_NOT_SUPPORTED ;} +EXPORT_API int maps_plugin_get_max_zoom_level(maps_view_h hView, int *max_zoom_level){return MAPS_ERROR_NOT_SUPPORTED ;} +EXPORT_API int maps_plugin_get_center(maps_view_h hView, maps_coordinates_h *center){return MAPS_ERROR_NOT_SUPPORTED ;} + +/*END MASSIVE TODO: + */ + +EXPORT_API int maps_plugin_init_module(maps_plugin_h *plugin, const char* module) { if (!plugin) return MAPS_ERROR_INVALID_PARAMETER; @@ -166,6 +199,11 @@ EXPORT_API int maps_plugin_init(maps_plugin_h *plugin) return __convert_to_maps_error(ret); } +EXPORT_API int maps_plugin_init(maps_plugin_h *plugin) +{ + return maps_plugin_init_module(plugin, NULL); +} + EXPORT_API int maps_plugin_shutdown(maps_plugin_h plugin) { MAPS_LOGD("PLUGIN SHUTDOWN"); @@ -242,7 +280,7 @@ EXPORT_API int maps_plugin_get_info(maps_plugin_info_h *info) return MAPS_ERROR_INVALID_PARAMETER; maps_plugin_info_create(info); - maps_plugin_info_set_provider_name(*info, "MAPZEN"); + maps_plugin_info_set_provider_name(*info, "mapzen"); return MAPS_ERROR_NONE; } @@ -570,13 +608,14 @@ static void __mapzen_reverse_geocode_cb(mapzen_error_e result, int request_id, m maps_address_h addr = NULL; maps_address_create(&addr); - maps_address_set_street(addr, address->street_add); - maps_address_set_city(addr, address->city); + //TODO: housenumber?? + maps_address_set_street(addr, address->street); + maps_address_set_city(addr, address->localadmin); maps_address_set_county(addr, address->county); - maps_address_set_state(addr, address->state); + maps_address_set_state(addr, address->region); maps_address_set_country(addr, address->country); - maps_address_set_country_code(addr, address->country_code); - maps_address_set_postal_code(addr, address->postal_code); + maps_address_set_country_code(addr, address->country_a); + maps_address_set_postal_code(addr, address->postalcode); calldata_reverse_geocode->callback(MAPS_ERROR_NONE, calldata_reverse_geocode->reqID, index, total_count, addr, calldata_reverse_geocode->data); } @@ -1030,14 +1069,14 @@ static void __mapzen_place_search_cb(mapzen_error_e result, int request_id, GLis maps_address_h addr = NULL; maps_address_create(&addr); - maps_address_set_street(addr, mapzen_place->address->street_add); - maps_address_set_building_number(addr, mapzen_place->address->building_number); - maps_address_set_city(addr, mapzen_place->address->city); + maps_address_set_street(addr, mapzen_place->address->street); + maps_address_set_building_number(addr, mapzen_place->address->housenumber); + maps_address_set_city(addr, mapzen_place->address->localadmin); maps_address_set_county(addr, mapzen_place->address->county); - maps_address_set_state(addr, mapzen_place->address->state); + maps_address_set_state(addr, mapzen_place->address->region); maps_address_set_country(addr, mapzen_place->address->country); - maps_address_set_country_code(addr, mapzen_place->address->country_code); - maps_address_set_postal_code(addr, mapzen_place->address->postal_code); + maps_address_set_country_code(addr, mapzen_place->address->country_a); + maps_address_set_postal_code(addr, mapzen_place->address->postalcode); maps_address_set_freetext(addr, mapzen_place->display_name); maps_place_set_address(place, addr); -- 2.7.4