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);
24 if (--ref_cnt > 0) return;
26 if (!maps_place_filter) return;
27 maps_place_filter_destroy(maps_place_filter);
28 maps_place_filter = NULL;
31 static void cleanup_callback(int error)
42 * callback functions for APIs
46 static bool __maps_place_attribute_cb(int index, int total, maps_place_attribute_h attribute, void *user_data)
48 if (!attribute) return false;
51 LOG_START("attributes [%d/%d] = {", MIN(index+1, total), total);
53 if (maps_place_attribute_get_id(attribute, &lv.strval) == MAPS_ERROR_NONE)
54 LOG_PRINT("%sid = %s", LOG_PREFIX, lv.strval);
56 if (maps_place_attribute_get_label(attribute, &lv.strval) == MAPS_ERROR_NONE)
57 LOG_PRINT("%slabel = %s", LOG_PREFIX, lv.strval);
59 if (maps_place_attribute_get_text(attribute, &lv.strval) == MAPS_ERROR_NONE)
60 LOG_PRINT("%stext = %s", LOG_PREFIX, lv.strval);
62 maps_place_attribute_destroy(attribute);
68 static bool __maps_place_categories_cb(int index, int total, maps_place_category_h category, void *user_data)
70 if (!category) return false;
72 LOG_START("categories [%d/%d] = {", MIN(index+1, total), total);
74 if (maps_place_category_get_name(category, &lv.strval) == MAPS_ERROR_NONE)
75 LOG_PRINT("%sname = %s", LOG_PREFIX, lv.strval);
77 if (maps_place_category_get_id(category, &lv.strval) == MAPS_ERROR_NONE)
78 LOG_PRINT("%sid = %s", LOG_PREFIX, lv.strval);
80 if (maps_place_category_get_url(category, &lv.strval) == MAPS_ERROR_NONE)
81 LOG_PRINT("%surl = %s", LOG_PREFIX, lv.strval);
83 maps_place_category_destroy(category);
89 static bool __maps_place_contacts_cb(int index, int total, maps_place_contact_h contact, void *user_data)
91 if (!contact) return false;
93 LOG_START("contacts [%d/%d] = {", MIN(index+1, total), total);
95 if (maps_place_contact_get_label(contact, &lv.strval) == MAPS_ERROR_NONE)
96 LOG_PRINT("%slabel = %s", LOG_PREFIX, lv.strval);
98 if (maps_place_contact_get_type(contact, &lv.strval) == MAPS_ERROR_NONE)
99 LOG_PRINT("%stype = %s", LOG_PREFIX, lv.strval);
101 if (maps_place_contact_get_value(contact, &lv.strval) == MAPS_ERROR_NONE)
102 LOG_PRINT("%svalue = %s", LOG_PREFIX, lv.strval);
104 maps_place_contact_destroy(contact);
110 static bool __maps_place_editorials_cb(int index, int total, maps_place_editorial_h editorial, void *user_data)
112 if (!editorial) return false;
114 LOG_START("editorial [%d/%d] = {", MIN(index+1, total), total);
116 if (maps_place_editorial_get_description(editorial, &lv.strval) == MAPS_ERROR_NONE)
117 LOG_PRINT("%sdescription = %s", LOG_PREFIX, lv.strval);
119 if (maps_place_editorial_get_language(editorial, &lv.strval) == MAPS_ERROR_NONE)
120 LOG_PRINT("%slanguage = %s", LOG_PREFIX, lv.strval);
122 maps_place_media_h media = NULL;
123 if (maps_place_editorial_get_media(editorial, &media) == MAPS_ERROR_NONE) {
124 log_place_media(" ", media);
125 maps_place_media_destroy(media);
128 maps_place_editorial_destroy(editorial);
134 static bool __maps_place_images_cb(int index, int total, maps_place_image_h image, void *user_data)
136 if (!image) return false;
138 LOG_START("image [%d/%d] = {", MIN(index+1, total), total);
140 if (maps_place_image_get_id(image, &lv.strval) == MAPS_ERROR_NONE)
141 LOG_PRINT("%sid = %s", LOG_PREFIX, lv.strval);
143 if (maps_place_image_get_url(image, &lv.strval) == MAPS_ERROR_NONE)
144 LOG_PRINT("%surl = %s", LOG_PREFIX, lv.strval);
146 if (maps_place_image_get_width(image, &lv.intval) == MAPS_ERROR_NONE)
147 LOG_PRINT("%swidth = %d", LOG_PREFIX, lv.intval);
149 if (maps_place_image_get_height(image, &lv.intval) == MAPS_ERROR_NONE)
150 LOG_PRINT("%sheight = %d", LOG_PREFIX, lv.intval);
152 maps_place_link_object_h user_link = NULL;
153 if (maps_place_image_get_user_link(image, &user_link) == MAPS_ERROR_NONE) {
154 log_place_link_object(LOG_PREFIX, "user link", user_link);
155 maps_place_link_object_destroy(user_link);
158 maps_place_media_h media = NULL;
159 if (maps_place_image_get_media(image, &media) == MAPS_ERROR_NONE) {
160 log_place_media(LOG_PREFIX, media);
161 maps_place_media_destroy(media);
164 maps_place_image_destroy(image);
170 static bool __maps_place_properties_cb(int index, int total, char* key, void* value, void* user_data)
173 LOG_START("properties [%d/%d] %s = %s", MIN(index+1, total), total, (char*)key, (char*)value);
178 static bool __maps_place_reviews_cb(int index, int total, maps_place_review_h review, void *user_data)
180 if (!review) return false;
182 LOG_START("review [%d/%d] {", MIN(index+1, total), total);
184 if (maps_place_review_get_date(review, &lv.strval) == MAPS_ERROR_NONE)
185 LOG_PRINT("%sdate = %s", LOG_PREFIX, lv.strval);
187 if (maps_place_review_get_title(review, &lv.strval) == MAPS_ERROR_NONE)
188 LOG_PRINT("%stitle = %s", LOG_PREFIX, lv.strval);
190 if (maps_place_review_get_rating(review, &lv.dblval) == MAPS_ERROR_NONE)
191 LOG_PRINT("%srating = %.2f", LOG_PREFIX, lv.dblval);
193 if (maps_place_review_get_description(review, &lv.strval) == MAPS_ERROR_NONE)
194 LOG_PRINT("%sdescription = %s", LOG_PREFIX, lv.strval);
196 maps_place_media_h media = NULL;
197 if (maps_place_review_get_media(review, &media) == MAPS_ERROR_NONE) {
198 log_place_media(LOG_PREFIX, media);
199 maps_place_media_destroy(media);
202 maps_place_link_object_h user_link = NULL;
203 if (maps_place_review_get_user_link(review, &user_link) == MAPS_ERROR_NONE) {
204 log_place_link_object(LOG_PREFIX, "user link", user_link);
205 maps_place_link_object_destroy(user_link);
208 maps_place_review_destroy(review);
214 static bool __log_place(char *prefix, maps_place_h place)
219 if (maps_place_get_id(place, &lv.strval) == MAPS_ERROR_NONE)
220 LOG_PRINT("%sid = %s", prefix, lv.strval);
222 if (maps_place_get_name(place, &lv.strval) == MAPS_ERROR_NONE)
223 LOG_PRINT("%sname = %s", prefix, lv.strval);
225 if (maps_place_get_uri(place, &lv.strval) == MAPS_ERROR_NONE)
226 LOG_PRINT("%suri = %s", prefix, lv.strval);
228 maps_coordinates_h coord = NULL;
229 if (maps_place_get_location(place, &coord) == MAPS_ERROR_NONE) {
231 maps_coordinates_get_latitude(coord, &lat);
232 maps_coordinates_get_longitude(coord, &lng);
233 LOG_PRINT("%slocation = %f, %f", prefix, lat, lng);
234 maps_coordinates_destroy(coord);
238 maps_distance_unit_e distance_unit;
239 if (maps_place_get_distance(place, &distance) == MAPS_ERROR_NONE) {
240 maps_preference_get_distance_unit(maps_pref, &distance_unit);
241 LOG_PRINT("%sdistance = %d %s", prefix, distance, get_distance_unit_string(distance_unit));
244 maps_address_h address = NULL;
245 if (maps_place_get_address(place, &address) == MAPS_ERROR_NONE) {
246 log_address(prefix, address);
247 maps_address_destroy(address);
250 maps_place_rating_h rating = NULL;
251 if (maps_place_get_rating(place, &rating) == MAPS_ERROR_NONE && rating) {
252 log_place_rating(prefix, rating);
253 maps_place_rating_destroy(rating);
256 int ret = maps_place_foreach_property(place, __maps_place_properties_cb, NULL);
257 if (ret != MAPS_ERROR_NONE && ret != MAPS_ERROR_NOT_FOUND)
258 LOG_PRINT("%sproperties : error (%d)", prefix, ret);
260 ret = maps_place_foreach_category(place, __maps_place_categories_cb, NULL);
261 if (ret != MAPS_ERROR_NONE && ret != MAPS_ERROR_NOT_FOUND)
262 LOG_PRINT("%scategories : error (%d)", prefix, ret);
264 ret = maps_place_foreach_attribute(place, __maps_place_attribute_cb, NULL);
265 if (ret != MAPS_ERROR_NONE && ret != MAPS_ERROR_NOT_FOUND)
266 LOG_PRINT("%sattributes : error (%d)", prefix, ret);
268 ret = maps_place_foreach_contact(place, __maps_place_contacts_cb, NULL);
269 if (ret != MAPS_ERROR_NONE && ret != MAPS_ERROR_NOT_FOUND)
270 LOG_PRINT("%scontacts : error (%d)", prefix, ret);
272 ret = maps_place_foreach_editorial(place, __maps_place_editorials_cb, NULL);
273 if (ret != MAPS_ERROR_NONE && ret != MAPS_ERROR_NOT_FOUND)
274 LOG_PRINT("%seditorials : error (%d)", prefix, ret);
276 ret = maps_place_foreach_image(place, __maps_place_images_cb, NULL);
277 if (ret != MAPS_ERROR_NONE && ret != MAPS_ERROR_NOT_FOUND)
278 LOG_PRINT("%simages : error (%d)", prefix, ret);
280 ret = maps_place_foreach_review(place, __maps_place_reviews_cb, NULL);
281 if (ret != MAPS_ERROR_NONE && ret != MAPS_ERROR_NOT_FOUND)
282 LOG_PRINT("%sreviews : error (%d)", prefix, ret);
288 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)
291 LOG_START_TITLE("%s [%d/%d] ", (user_data ? (char*)user_data : __FUNCTION__), MIN(index+1, total), total);
294 cleanup_callback(error);
298 __log_place("", place);
299 maps_place_destroy(place);
303 if (index == total - 1)
304 cleanup_callback(error);
309 static bool __maps_place_cb(int index, maps_place_h place, void *user_data)
312 LOG_START_TITLE("%s [%d] ", (user_data ? (char*)user_data : __FUNCTION__), index+1);
314 __log_place("", place);
315 maps_place_destroy(place);
321 static void __maps_service_search_place_list_cb(maps_error_e error,
322 int request_id, int total, maps_place_list_h place_list, void *user_data)
326 cleanup_callback(error);
329 maps_place_list_foreach(place_list, __maps_place_cb, user_data);
330 cleanup_callback(error);
338 * query functions to use APIs
342 int maps_test_search_place(maps_service_h maps_svc)
345 int request_id = 0, error;
347 maps_coordinates_h coordinates;
348 maps_coordinates_create(48.85784, 2.29516, &coordinates);
350 maps_place_filter_set_place_name(maps_place_filter, "Berlin");
351 maps_preference_set_property(maps_pref, MAPS_PLACE_FILTER_SORT_BY, "distance");
353 error = maps_service_search_place(maps_svc, coordinates, 5, maps_place_filter, maps_pref,
354 __maps_service_search_place_cb, "Search Place", &request_id);
356 maps_coordinates_destroy(coordinates);
358 if (error != MAPS_ERROR_NONE)
363 int maps_test_search_place_by_address(maps_service_h maps_svc)
366 int request_id = 0, error;
368 maps_coordinates_h top_left, bottom_right;
370 maps_coordinates_create(15.665354, 74.311523, &top_left);
371 maps_coordinates_create(10.617418, 79.145508, &bottom_right);
372 maps_area_create_rectangle(top_left, bottom_right, &area);
374 error = maps_service_search_place_by_address(maps_svc, "Bengaluru",
375 area, maps_place_filter, maps_pref,
376 __maps_service_search_place_cb, "Search Place By Address", &request_id);
378 maps_coordinates_destroy(top_left);
379 maps_coordinates_destroy(bottom_right);
380 maps_area_destroy(area);
382 if (error != MAPS_ERROR_NONE)
387 int maps_test_search_place_by_area(maps_service_h maps_svc)
390 int request_id = 0, error;
392 maps_coordinates_h top_left, bottom_right;
394 maps_coordinates_create(52.51605, 12.37691, &top_left);
395 maps_coordinates_create(54.12351, 14.22351, &bottom_right);
396 maps_area_create_rectangle(top_left, bottom_right, &area);
398 error = maps_service_search_place_by_area(maps_svc, area, maps_place_filter, maps_pref,
399 __maps_service_search_place_cb, "Search Place By Area", &request_id);
401 maps_coordinates_destroy(top_left);
402 maps_coordinates_destroy(bottom_right);
403 maps_area_destroy(area);
405 if (error != MAPS_ERROR_NONE)
411 int maps_test_search_place_list(maps_service_h maps_svc)
414 int request_id = 0, error;
416 maps_coordinates_h coordinates;
418 maps_coordinates_create(52.5167, 13.383, &coordinates);
419 maps_area_create_circle(coordinates, 5000, &area);
421 error = maps_service_search_place_list(maps_svc, area, maps_place_filter, maps_pref,
422 __maps_service_search_place_list_cb, "Search Place List", &request_id);
424 maps_coordinates_destroy(coordinates);
425 maps_area_destroy(area);
427 if (error != MAPS_ERROR_NONE)
433 int maps_test_search_place_cancel(maps_service_h maps_svc)
436 int request_id = 0, error;
438 maps_coordinates_h coordinates;
439 maps_coordinates_create(48.85784, 2.29516, &coordinates);
441 maps_place_filter_set_place_name(maps_place_filter, "Berlin");
442 maps_preference_set_property(maps_pref, MAPS_PLACE_FILTER_SORT_BY, "distance");
444 error = maps_service_search_place(maps_svc, coordinates, 5, maps_place_filter, maps_pref,
445 __maps_service_search_place_cb, "Search Place", &request_id);
447 maps_service_cancel_request(maps_svc, request_id);
448 maps_coordinates_destroy(coordinates);
450 if (error != MAPS_ERROR_NONE)