2 #include "maps_test_search_place.h"
3 #include "maps_test_log.h"
4 #include "maps_test_util.h"
6 static maps_place_filter_h maps_place_filter = NULL;
7 static int ref_cnt = 0;
8 static int unlimited_cnt = 0;
13 if (ref_cnt++) return;
15 if (maps_place_filter) return;
16 maps_preference_set_max_results(maps_pref, 5);
17 maps_preference_set_language(maps_pref, "ko-KR");
18 maps_place_filter_create(&maps_place_filter);
21 static void cleanup(bool result)
26 if (--ref_cnt > 0) return;
28 if (!maps_place_filter) return;
29 maps_place_filter_destroy(maps_place_filter);
30 maps_place_filter = NULL;
39 * callback functions for APIs
43 static bool __maps_place_attribute_cb(int index, int total, maps_place_attribute_h attribute, void *user_data)
45 if (!attribute) return false;
48 LOG_START("attributes [%d/%d] = {", MIN(index+1, total), total);
50 if (maps_place_attribute_get_id(attribute, &lv.strval) == MAPS_ERROR_NONE)
51 LOG_PRINT("%sid = %s", LOG_PREFIX, lv.strval);
53 if (maps_place_attribute_get_label(attribute, &lv.strval) == MAPS_ERROR_NONE)
54 LOG_PRINT("%slabel = %s", LOG_PREFIX, lv.strval);
56 if (maps_place_attribute_get_text(attribute, &lv.strval) == MAPS_ERROR_NONE)
57 LOG_PRINT("%stext = %s", LOG_PREFIX, lv.strval);
59 maps_place_attribute_destroy(attribute);
65 static bool __maps_place_categories_cb(int index, int total, maps_place_category_h category, void *user_data)
67 if (!category) return false;
69 LOG_START("categories [%d/%d] = {", MIN(index+1, total), total);
71 if (maps_place_category_get_name(category, &lv.strval) == MAPS_ERROR_NONE)
72 LOG_PRINT("%sname = %s", LOG_PREFIX, lv.strval);
74 if (maps_place_category_get_id(category, &lv.strval) == MAPS_ERROR_NONE)
75 LOG_PRINT("%sid = %s", LOG_PREFIX, lv.strval);
77 if (maps_place_category_get_url(category, &lv.strval) == MAPS_ERROR_NONE)
78 LOG_PRINT("%surl = %s", LOG_PREFIX, lv.strval);
80 maps_place_category_destroy(category);
86 static bool __maps_place_contacts_cb(int index, int total, maps_place_contact_h contact, void *user_data)
88 if (!contact) return false;
90 LOG_START("contacts [%d/%d] = {", MIN(index+1, total), total);
92 if (maps_place_contact_get_label(contact, &lv.strval) == MAPS_ERROR_NONE)
93 LOG_PRINT("%slabel = %s", LOG_PREFIX, lv.strval);
95 if (maps_place_contact_get_type(contact, &lv.strval) == MAPS_ERROR_NONE)
96 LOG_PRINT("%stype = %s", LOG_PREFIX, lv.strval);
98 if (maps_place_contact_get_value(contact, &lv.strval) == MAPS_ERROR_NONE)
99 LOG_PRINT("%svalue = %s", LOG_PREFIX, lv.strval);
101 maps_place_contact_destroy(contact);
107 static bool __maps_place_editorials_cb(int index, int total, maps_place_editorial_h editorial, void *user_data)
109 if (!editorial) return false;
111 LOG_START("editorial [%d/%d] = {", MIN(index+1, total), total);
113 if (maps_place_editorial_get_description(editorial, &lv.strval) == MAPS_ERROR_NONE)
114 LOG_PRINT("%sdescription = %s", LOG_PREFIX, lv.strval);
116 if (maps_place_editorial_get_language(editorial, &lv.strval) == MAPS_ERROR_NONE)
117 LOG_PRINT("%slanguage = %s", LOG_PREFIX, lv.strval);
119 maps_place_media_h media = NULL;
120 if (maps_place_editorial_get_media(editorial, &media) == MAPS_ERROR_NONE) {
121 log_place_media(" ", media);
122 maps_place_media_destroy(media);
125 maps_place_editorial_destroy(editorial);
131 static bool __maps_place_images_cb(int index, int total, maps_place_image_h image, void *user_data)
133 if (!image) return false;
135 LOG_START("image [%d/%d] = {", MIN(index+1, total), total);
137 if (maps_place_image_get_id(image, &lv.strval) == MAPS_ERROR_NONE)
138 LOG_PRINT("%sid = %s", LOG_PREFIX, lv.strval);
140 if (maps_place_image_get_url(image, &lv.strval) == MAPS_ERROR_NONE)
141 LOG_PRINT("%surl = %s", LOG_PREFIX, lv.strval);
143 if (maps_place_image_get_width(image, &lv.intval) == MAPS_ERROR_NONE)
144 LOG_PRINT("%swidth = %d", LOG_PREFIX, lv.intval);
146 if (maps_place_image_get_height(image, &lv.intval) == MAPS_ERROR_NONE)
147 LOG_PRINT("%sheight = %d", LOG_PREFIX, lv.intval);
149 maps_place_link_object_h user_link = NULL;
150 if (maps_place_image_get_user_link(image, &user_link) == MAPS_ERROR_NONE) {
151 log_place_link_object(LOG_PREFIX, "user link", user_link);
152 maps_place_link_object_destroy(user_link);
155 maps_place_media_h media = NULL;
156 if (maps_place_image_get_media(image, &media) == MAPS_ERROR_NONE) {
157 log_place_media(LOG_PREFIX, media);
158 maps_place_media_destroy(media);
161 maps_place_image_destroy(image);
167 static bool __maps_place_properties_cb(int index, int total, char* key, void* value, void* user_data)
170 LOG_START("properties [%d/%d] %s = %s", MIN(index+1, total), total, (char*)key, (char*)value);
175 static bool __maps_place_reviews_cb(int index, int total, maps_place_review_h review, void *user_data)
177 if (!review) return false;
179 LOG_START("review [%d/%d] {", MIN(index+1, total), total);
181 if (maps_place_review_get_date(review, &lv.strval) == MAPS_ERROR_NONE)
182 LOG_PRINT("%sdate = %s", LOG_PREFIX, lv.strval);
184 if (maps_place_review_get_title(review, &lv.strval) == MAPS_ERROR_NONE)
185 LOG_PRINT("%stitle = %s", LOG_PREFIX, lv.strval);
187 if (maps_place_review_get_rating(review, &lv.dblval) == MAPS_ERROR_NONE)
188 LOG_PRINT("%srating = %.2f", LOG_PREFIX, lv.dblval);
190 if (maps_place_review_get_description(review, &lv.strval) == MAPS_ERROR_NONE)
191 LOG_PRINT("%sdescription = %s", LOG_PREFIX, lv.strval);
193 maps_place_media_h media = NULL;
194 if (maps_place_review_get_media(review, &media) == MAPS_ERROR_NONE) {
195 log_place_media(LOG_PREFIX, media);
196 maps_place_media_destroy(media);
199 maps_place_link_object_h user_link = NULL;
200 if (maps_place_review_get_user_link(review, &user_link) == MAPS_ERROR_NONE) {
201 log_place_link_object(LOG_PREFIX, "user link", user_link);
202 maps_place_link_object_destroy(user_link);
205 maps_place_review_destroy(review);
211 static bool __log_place(char *prefix, maps_place_h place)
216 if (maps_place_get_id(place, &lv.strval) == MAPS_ERROR_NONE)
217 LOG_PRINT("%sid = %s", prefix, lv.strval);
219 if (maps_place_get_name(place, &lv.strval) == MAPS_ERROR_NONE)
220 LOG_PRINT("%sname = %s", prefix, lv.strval);
222 if (maps_place_get_uri(place, &lv.strval) == MAPS_ERROR_NONE)
223 LOG_PRINT("%suri = %s", prefix, lv.strval);
225 maps_coordinates_h coord = NULL;
226 if (maps_place_get_location(place, &coord) == MAPS_ERROR_NONE) {
228 maps_coordinates_get_latitude(coord, &lat);
229 maps_coordinates_get_longitude(coord, &lng);
230 LOG_PRINT("%slocation = %f, %f", prefix, lat, lng);
231 maps_coordinates_destroy(coord);
235 maps_distance_unit_e distance_unit;
236 if (maps_place_get_distance(place, &distance) == MAPS_ERROR_NONE) {
237 maps_preference_get_distance_unit(maps_pref, &distance_unit);
238 LOG_PRINT("%sdistance = %d %s", prefix, distance, get_distance_unit_string(distance_unit));
241 maps_address_h address = NULL;
242 if (maps_place_get_address(place, &address) == MAPS_ERROR_NONE) {
243 log_address(prefix, address);
244 maps_address_destroy(address);
247 maps_place_rating_h rating = NULL;
248 if (maps_place_get_rating(place, &rating) == MAPS_ERROR_NONE && rating) {
249 log_place_rating(prefix, rating);
250 maps_place_rating_destroy(rating);
253 int ret = maps_place_foreach_property(place, __maps_place_properties_cb, NULL);
254 if (ret != MAPS_ERROR_NONE && ret != MAPS_ERROR_NOT_FOUND)
255 LOG_PRINT("%sproperties : error (%d)", prefix, ret);
257 ret = maps_place_foreach_category(place, __maps_place_categories_cb, NULL);
258 if (ret != MAPS_ERROR_NONE && ret != MAPS_ERROR_NOT_FOUND)
259 LOG_PRINT("%scategories : error (%d)", prefix, ret);
261 ret = maps_place_foreach_attribute(place, __maps_place_attribute_cb, NULL);
262 if (ret != MAPS_ERROR_NONE && ret != MAPS_ERROR_NOT_FOUND)
263 LOG_PRINT("%sattributes : error (%d)", prefix, ret);
265 ret = maps_place_foreach_contact(place, __maps_place_contacts_cb, NULL);
266 if (ret != MAPS_ERROR_NONE && ret != MAPS_ERROR_NOT_FOUND)
267 LOG_PRINT("%scontacts : error (%d)", prefix, ret);
269 ret = maps_place_foreach_editorial(place, __maps_place_editorials_cb, NULL);
270 if (ret != MAPS_ERROR_NONE && ret != MAPS_ERROR_NOT_FOUND)
271 LOG_PRINT("%seditorials : error (%d)", prefix, ret);
273 ret = maps_place_foreach_image(place, __maps_place_images_cb, NULL);
274 if (ret != MAPS_ERROR_NONE && ret != MAPS_ERROR_NOT_FOUND)
275 LOG_PRINT("%simages : error (%d)", prefix, ret);
277 ret = maps_place_foreach_review(place, __maps_place_reviews_cb, NULL);
278 if (ret != MAPS_ERROR_NONE && ret != MAPS_ERROR_NOT_FOUND)
279 LOG_PRINT("%sreviews : error (%d)", prefix, ret);
285 static bool __maps_service_search_place_cb(maps_error_e error, int request_id , int index, int total, maps_place_h place, void* user_data)
288 LOG_START_TITLE("%s [%d/%d] ", (user_data ? (char*)user_data : __FUNCTION__), MIN(index+1, total), total);
291 LOG_PRINT("error=%d", error);
296 __log_place("", place);
297 maps_place_destroy(place);
301 if (index == total - 1)
307 static bool __maps_place_cb(int index, maps_place_h place, void *user_data)
310 LOG_START_TITLE("%s [%d] ", (user_data ? (char*)user_data : __FUNCTION__), index+1);
312 __log_place("", place);
313 maps_place_destroy(place);
319 static void __maps_service_search_place_list_cb(maps_error_e error,
320 int request_id, int total, maps_place_list_h place_list, void *user_data)
323 LOGD("error=%d", error);
327 maps_place_list_foreach(place_list, __maps_place_cb, user_data);
336 * query functions to use APIs
340 int maps_test_search_place(maps_service_h maps_svc)
343 int request_id = 0, error;
345 maps_coordinates_h coordinates;
346 maps_coordinates_create(48.85784, 2.29516, &coordinates);
348 maps_place_filter_set_place_name(maps_place_filter, "Berlin");
349 maps_preference_set_property(maps_pref, MAPS_PLACE_FILTER_SORT_BY, "distance");
351 error = maps_service_search_place(maps_svc, coordinates, 5, maps_place_filter, maps_pref,
352 __maps_service_search_place_cb, "Search Place", &request_id);
354 maps_coordinates_destroy(coordinates);
356 if (error != MAPS_ERROR_NONE)
361 int maps_test_search_place_by_address(maps_service_h maps_svc)
364 int request_id = 0, error;
366 maps_coordinates_h top_left, bottom_right;
368 maps_coordinates_create(15.665354, 74.311523, &top_left);
369 maps_coordinates_create(10.617418, 79.145508, &bottom_right);
370 maps_area_create_rectangle(top_left, bottom_right, &area);
372 error = maps_service_search_place_by_address(maps_svc, "Bengaluru",
373 area, maps_place_filter, maps_pref,
374 __maps_service_search_place_cb, "Search Place By Address", &request_id);
376 maps_coordinates_destroy(top_left);
377 maps_coordinates_destroy(bottom_right);
378 maps_area_destroy(area);
380 if (error != MAPS_ERROR_NONE)
385 int maps_test_search_place_by_area(maps_service_h maps_svc)
388 int request_id = 0, error;
390 maps_coordinates_h top_left, bottom_right;
392 maps_coordinates_create(15.665354, 74.311523, &top_left);
393 maps_coordinates_create(10.617418, 79.145508, &bottom_right);
394 maps_area_create_rectangle(top_left, bottom_right, &area);
396 error = maps_service_search_place_by_area(maps_svc, area, maps_place_filter, maps_pref,
397 __maps_service_search_place_cb, "Search Place By Area", &request_id);
399 maps_coordinates_destroy(top_left);
400 maps_coordinates_destroy(bottom_right);
401 maps_area_destroy(area);
403 if (error != MAPS_ERROR_NONE)
409 int maps_test_search_place_list(maps_service_h maps_svc)
412 int request_id = 0, error;
414 maps_coordinates_h coordinates;
416 maps_coordinates_create(52.5167, 13.383, &coordinates);
417 maps_area_create_circle(coordinates, 5000, &area);
419 error = maps_service_search_place_list(maps_svc, area, maps_place_filter, maps_pref,
420 __maps_service_search_place_list_cb, "Search Place List", &request_id);
422 maps_coordinates_destroy(coordinates);
423 maps_area_destroy(area);
425 if (error != MAPS_ERROR_NONE)