4 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Youngae Kang <youngae.kang@samsung.com>, Yunhan Kim <yhan.kim@samsung.com>,
7 * Genie Kim <daejins.kim@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
24 #include <glib/gprintf.h>
25 #include <gconf/gconf-client.h>
26 #include <location-map-service.h>
27 #include "location-api-test-util.h"
30 LocationMapObject* map_obj = NULL;
31 static GMainLoop *g_mainloop = NULL;
33 #define LOCATION_API_TEST_JSON_FILE "/opt/data/location-api-test.json"
35 static gpointer GmainThread(gpointer data)
37 g_mainloop = g_main_loop_new (NULL, FALSE);
38 g_printf("\n...Entering GMain Loop to Receive Notifications....\n");
39 g_main_loop_run (g_mainloop);
40 g_main_loop_unref (g_mainloop);
46 static void GetLocationError(char str[STR_MAX], int ret)
50 case LOCATION_ERROR_NONE:
51 g_utf8_strncpy(str, "LOCATION_ERROR_NONE", STR_MAX);
53 case LOCATION_ERROR_NOT_ALLOWED:
54 g_utf8_strncpy(str, "LOCATION_ERROR_NOT_ALLOWED", STR_MAX);
56 case LOCATION_ERROR_NOT_AVAILABLE:
57 g_utf8_strncpy(str, "LOCATION_ERROR_NOT_AVAILABLE", STR_MAX);
59 case LOCATION_ERROR_NETWORK_FAILED:
60 g_utf8_strncpy(str, "LOCATION_ERROR_NETWORK_FAILED", STR_MAX);
62 case LOCATION_ERROR_NETWORK_NOT_CONNECTED:
63 g_utf8_strncpy(str, "LOCATION_ERROR_NETWORK_NOT_CONNECTED", STR_MAX);
65 case LOCATION_ERROR_CONFIGURATION:
66 g_utf8_strncpy(str, "LOCATION_ERROR_CONFIGURATION", STR_MAX);
68 case LOCATION_ERROR_PARAMETER:
69 g_utf8_strncpy(str, "LOCATION_ERROR_PARAMETER", STR_MAX);
71 case LOCATION_ERROR_UNKNOWN:
72 g_utf8_strncpy(str, "LOCATION_ERROR_UNKNOWN", STR_MAX);
74 case LOCATION_ERROR_NOT_SUPPORTED:
75 g_utf8_strncpy(str, "LOCATION_ERROR_UNKNOWN", STR_MAX);
78 g_utf8_strncpy(str, "Error: undefined error code", STR_MAX);
82 static void GetAccuracyLevel(char str[STR_MAX], LocationAccuracyLevel acc_level)
85 case LOCATION_ACCURACY_LEVEL_NONE:
86 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_NONE", STR_MAX);
88 case LOCATION_ACCURACY_LEVEL_COUNTRY:
89 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_COUNTRY", STR_MAX);
91 case LOCATION_ACCURACY_LEVEL_REGION:
92 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_REGION", STR_MAX);
94 case LOCATION_ACCURACY_LEVEL_LOCALITY:
95 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_LOCALITY", STR_MAX);
97 case LOCATION_ACCURACY_LEVEL_POSTALCODE:
98 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_POSTALCODE", STR_MAX);
100 case LOCATION_ACCURACY_LEVEL_STREET:
101 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_STREET", STR_MAX);
103 case LOCATION_ACCURACY_LEVEL_DETAILED:
104 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_DETAILED", STR_MAX);
107 g_utf8_strncpy(str, "Error: undefined accuracy level", STR_MAX);
111 static void SelectOpt(char* buf)
114 fgets(buf, 255, stdin);
115 iLen = g_utf8_strlen(buf, -1);
119 static int PromptInt()
123 fgets(buf, 255, stdin);
124 buf[strlen(buf)-1]='\0';
125 ret = g_ascii_strtoll(buf, NULL, 10);
129 static double PromptDB()
133 fgets(buf, 255, stdin);
134 buf[strlen(buf)-1]='\0';
135 ret = g_ascii_strtod(buf, NULL);
139 static void PrintProperty (LocationObject* loc)
143 LocationMethod method = LOCATION_METHOD_NONE;
144 gchar method_str[STR_MAX] = {0, };
146 gchar* devname = NULL;
148 g_object_get(loc, "method", &method, NULL);
149 GetMethod(method_str, method);
150 g_printf("method[%s] ", method_str);
152 if (LOCATION_METHOD_GPS == method) {
153 g_object_get(loc, "dev-name", &devname, NULL);
155 g_printf("dev-name[%s] ", devname);
162 static void _print_property (gpointer data, gpointer user_data)
164 LocationLandmark *landmark = (LocationLandmark *)user_data;
165 gpointer key = (gpointer)data;
166 gpointer value = NULL;
169 value = (gpointer)location_landmark_get_property(landmark, key);
170 g_printf(", [%s:%s]", (gchar*) key, (gchar*) value);
175 __plugin_print_poi_list (gpointer data, gpointer user_data)
177 LocationLandmark *landmark = (LocationLandmark *)data;
178 LocationPosition *pos = location_landmark_get_position (landmark);
179 LocationAddress *addr = location_landmark_get_address (landmark);
181 g_printf ("[ID:%d], [NAME:%s], phone[%s],pos[%f:%f], addr[%s:%s:%s:%s:%s]",
182 location_landmark_get_id (landmark),
183 location_landmark_get_name(landmark),
184 location_landmark_get_phone_number (landmark),
185 pos->latitude, pos->longitude,
186 addr->building_number, addr->city, addr->country_code, addr->district,
189 GList *key_list = location_landmark_get_property_key(landmark);
191 g_list_foreach(key_list, _print_property, landmark);
198 static void cb_poi(LocationError error, guint req_id, GList * landmark_list, gchar * error_code, gchar * error_msg, gpointer userdata)
200 g_printf("\n===== __location_POI_cb ======\n");
201 if (error != LOCATION_ERROR_NONE) {
202 g_printf("Failed :%d\n", error);
205 g_printf("Success, poi_list[0x%x] user_data[0x%x] req_id[%d]\n", (unsigned int)landmark_list, (unsigned int)userdata, req_id);
206 g_list_foreach (landmark_list, __plugin_print_poi_list, NULL);
208 if (error_code && error_msg) {
209 g_printf("__location_POI_cb: error_code[%s], error_msg[%s]\n", error_code, error_msg);
212 static void PrintStepInfo(const LocationRouteStep *step)
214 const LocationPosition *start = location_route_step_get_start_point(step);
215 gdouble start_lat = 0;
216 gdouble start_lon = 0;
218 start_lat = start->latitude;
219 start_lon = start->longitude;
221 g_printf("Step start position NULL\n");
223 const LocationPosition *end = location_route_step_get_end_point(step);
227 end_lat = end->latitude;
228 end_lon = end->longitude;
230 g_printf("Step end position NULL\n");
232 const gchar *inst = location_route_step_get_instruction(step);
234 g_printf("Step: start(%f/%f), end(%f/%f), instruction(%s)\n", start_lat, start_lon, end_lat, end_lon, inst);
237 static void cb_print_route_step (gpointer data, gpointer user_data)
239 g_printf("+++Step begin\n");
240 LocationRouteStep *step = (LocationRouteStep *)data;
243 g_printf("---Step end\n");
246 static void cb_print_route_segment (gpointer data, gpointer user_data)
248 g_printf("++Segment begin\n");
249 LocationRouteSegment *seg = (LocationRouteSegment *)data;
250 gdouble seg_dist = location_route_segment_get_distance(seg);
251 glong seg_duration = location_route_segment_get_duration(seg);
252 const LocationPosition *start = location_route_segment_get_start_point(seg);
253 gdouble start_lat = 0;
254 gdouble start_lon = 0;
256 start_lat = start->latitude;
257 start_lon = start->longitude;
259 g_printf("Segment start position NULL\n");
261 const LocationPosition *end = location_route_segment_get_end_point(seg);
265 end_lat = end->latitude;
266 end_lon = end->longitude;
268 g_printf("Segment end postion NULL\n");
270 g_printf("Segment info: Distance[%f], Duration[%ld], start(%f/%f), end(%f/%f)\n", seg_dist, seg_duration,
271 start_lat, start_lon, end_lat, end_lon);
273 GList *step_list = location_route_segment_get_route_step(seg);
274 GList *tmp_list = (GList *)step_list;
276 g_list_foreach(tmp_list, cb_print_route_step, NULL);
278 g_printf("--Segment end\n");
282 static void cb_print_route_list (gpointer data, gpointer user_data)
284 g_printf("+Route begin\n");
285 LocationRoute *route = (LocationRoute *)data;
287 const LocationPosition *start = location_route_get_origin(route);
288 gdouble start_lat = 0;
289 gdouble start_lon = 0;
291 start_lat = start->latitude;
292 start_lon = start->longitude;
294 g_printf("Route start position NULL\n");
296 const LocationPosition *end = location_route_get_destination(route);
300 end_lat = end->latitude;
301 end_lon = end->longitude;
303 g_printf("Route end position NULL\n");
305 g_printf("Route: start(%f/%f), end(%f/%f)\n", start_lat, start_lon, end_lat, end_lon);
307 gdouble distance = location_route_get_total_distance(route);
308 const gchar *dis_unit = location_route_get_distance_unit(route);
309 glong duration = location_route_get_total_duration(route);
310 const LocationBoundary *bound = location_route_get_bounding_box(route);
311 if (bound && bound->type == LOCATION_BOUNDARY_RECT) {
312 g_printf("RECT left top[%f-%f], right bottom[%f-%f]\n", bound->rect.left_top->latitude, bound->rect.left_top->longitude,
313 bound->rect.right_bottom->latitude, bound->rect.right_bottom->longitude);
315 g_printf("route boundary not exist, or not RECT\n");
317 g_printf ("Distance[%f], Distance unit[%s], Duration[%ld]\n", distance, dis_unit, duration);
319 GList *seg_list = location_route_get_route_segment(route);
321 g_list_foreach(seg_list, cb_print_route_segment, NULL);
324 g_printf("-Route end\n");
327 static void cb_route(LocationError error, guint req_id, GList * route_list, gchar * error_code, gchar * error_msg, gpointer userdata)
329 g_printf("\n===== cb_route ======\n");
330 if (error != LOCATION_ERROR_NONE) {
331 g_printf("Failed :%d\n", error);
335 g_printf("Success, poi_list[0x%x] user_data[0x%x] req_id[%d]\n", (unsigned int)route_list, (unsigned int)userdata, req_id);
338 g_list_foreach (route_list, cb_print_route_list, NULL);
340 if (error_code && error_msg) {
341 g_printf("cb_route: error_code[%s], error_msg[%s]\n", error_code, error_msg);
345 static void cb_address(LocationError error, LocationAddress *addr, LocationAccuracy *acc, gpointer userdata)
347 if (error != LOCATION_ERROR_NONE) {
348 g_printf("cb_address failed: error=%d\n", error);
352 g_printf("userdata[0x%x] building number: [%s], street: [%s], state: [%s], country code: [%s], city: [%s], district: [%s], postal code: [%s]\n",
353 (unsigned int)userdata, addr->building_number, addr->street, addr->state, addr->country_code, addr->city, addr->district, addr->postal_code);
354 GetAccuracyLevel(str, acc->level);
355 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
360 LocationPosition *pos;
361 LocationAddress *addr;
363 LocationPositionCB pos_cb;
364 LocationAddressCB addr_cb;
368 static gboolean idle_address_from_position_async(gpointer data)
370 IdleData* idle_data = (IdleData*)data;
372 int ret = location_map_get_address_from_position_async(idle_data->obj, idle_data->pos, idle_data->addr_cb, idle_data->user_data);
373 GetLocationError(str, ret);
374 g_printf("location_map_get_address_from_position_async: returned value [%s]\n", str);
375 location_position_free(idle_data->pos);
380 void _print_keys(gpointer value)
382 g_printf(" %s ", (gchar*) value);
385 static void print_map_service_keys (LocationObject *obj, int type)
389 location_map_get_provider_capability_key (obj, type, &key);
392 g_list_foreach (key, _print_keys, NULL);
395 g_list_free_full(key, g_free);
398 void _print_provider (gpointer data, gpointer user_data)
400 gchar *provider = (gchar *)data;
402 g_printf("[%s] is supported\n", provider);
405 static void print_menu()
407 g_printf("\n================================= Location API Test =================================\n");
408 g_printf("q. Exit\n");
409 g_printf("1. location_init\n");
410 g_printf("2. location_map_new for default \n");
411 g_printf("2a. location_map_new for decarta \n");
412 g_printf("2b. location_map_new for osm \n");
413 g_printf("3. location_map_free\n");
414 g_printf("4. location_map_get_address_from_position\n");
415 g_printf("4a. location_map_get_address_from_position_async\n");
416 g_printf("5. location_map_search_poi_with_keyword\n");
417 g_printf("5a. location_map_search_poi_with_category\n");
418 g_printf("5b. location_map_search_poi_with_poi_name\n");
419 g_printf("6. location_map_search_poi_by_area_with_keyword\n");
420 g_printf("6a. location_map_search_poi_by_area_with_category\n");
421 g_printf("6b. location_map_search_poi_by_area_with_poi_name\n");
422 g_printf("7. location_map_search_poi_by_addr_with_keyword\n");
423 g_printf("7a. location_map_search_poi_by_addr_with_category\n");
424 g_printf("7b. location_map_search_poi_by_addr_with_poi_name\n");
425 g_printf("8. location_map_search_poi_by_freeformed_address_with_keyword\n");
426 g_printf("8a. location_map_search_poi_by_freeformed_address_with_category\n");
427 g_printf("8b. location_map_search_poi_by_freeformed_address_with_poi_name\n");
428 g_printf("9. location_map_cancel_poi_request\n");
429 g_printf("10. location_map_request_route\n");
430 g_printf("10a. location_map_request_route for a long distance\n");
431 g_printf("11. location_map_cancel_route_request\n");
432 g_printf("12. location_map_is_supported_provider_capability\n");
433 g_printf("13. location_map_get_provider_capability_key\n");
434 g_printf("14. location_map_get_supported_providers \n");
435 g_printf("15. location_map_get_default_provider \n");
436 g_printf("16. location_map_set_provider \n");
437 g_printf("99. change map provider to default\n");
438 g_printf("99a. change map provider to decarta\n");
439 g_printf("99b. change map provider to osm\n");
441 g_printf("==================================== Property ====================================\n");
442 PrintProperty(map_obj);
443 g_printf("\n==================================================================================\n");
446 int main(int argc, char** argv)
454 // If application is executed by AUL, this is not needed.
455 g_setenv("PKG_NAME", "org.tizen.map-service-test", 1);
459 #if !GLIB_CHECK_VERSION (2, 31, 0)
460 if( !g_thread_supported() )
467 g_main = g_thread_create(GmainThread, NULL, TRUE, &gerr);
469 g_debug("Error create gmain thread: Err domain[%d] Err code[%d] Err msg[%s]",
470 gerr->domain, gerr->code, gerr->message);
475 g_printf("--- Start LBS Test App ---\n");
479 g_printf("Select option: ");
481 g_printf("======================================================================================\n");
482 if (0 == g_strcmp0 ("x", strOpt)) {
485 else if (0 == g_strcmp0("1",strOpt)) {
486 ret = location_init();
487 GetLocationError(str, ret);
488 g_printf("location_init: returned value [%s]\n", str);
489 } else if (0 == g_strcmp0("2",strOpt)) {
491 g_printf("Location object already existed: [0x%x]", (unsigned int)map_obj);
494 map_obj = location_map_new(NULL);
495 if(map_obj) g_printf("Success\n");
496 else g_printf("Failed\n");
497 } else if (0 == g_strcmp0("2a",strOpt)) {
499 g_printf("Location object already existed: [0x%x]", (unsigned int)map_obj);
502 map_obj = location_map_new("decarta");
503 if(map_obj) g_printf("Success\n");
504 else g_printf("Failed\n");
505 } else if (0 == g_strcmp0("2b",strOpt)) {
507 g_printf("Location object already existed: [0x%x]", (unsigned int)map_obj);
510 map_obj = location_map_new("osm");
511 if(map_obj) g_printf("Success\n");
512 else g_printf("Failed\n");
513 } else if (0 == g_strcmp0("3",strOpt)) {
514 ret = location_map_free (map_obj);
516 GetLocationError(str, ret);
517 g_printf("location_map_free: returned value [%s]\n", str);
518 }else if(0 == g_strcmp0("4",strOpt) ){
519 LocationPosition *pos = NULL;
520 LocationAddress *addr = NULL;
521 LocationAccuracy *acc = NULL;
522 g_printf("[0].San jose [1].Suwon HQ [*].Custom\n");
523 g_printf("Select Position: ");
524 int opt = PromptInt();
525 if(opt == 0) pos = location_position_new(0, 37.335276, -121.890059, 0, LOCATION_STATUS_2D_FIX);
526 else if(opt == 1) pos = location_position_new(0, 37.257809, 127.056383, 0, LOCATION_STATUS_2D_FIX);
528 g_printf("Input latitude: ");
529 gdouble lat = PromptDB();
530 g_printf("Input longitude: ");
531 gdouble lon = PromptDB();
532 pos = location_position_new(0, lat, lon, 0, LOCATION_STATUS_2D_FIX);
534 ret = location_map_get_address_from_position(map_obj, pos, &addr, &acc);
535 GetLocationError(str, ret);
536 g_printf("location_map_get_address_from_position: returned value [%s]\n", str);
537 if(ret == LOCATION_ERROR_NONE){
538 g_printf("building number: [%s], street: [%s], state: [%s], country code: [%s], city: [%s], district: [%s], postal code: [%s]\n",
539 addr->building_number, addr->street, addr->state, addr->country_code, addr->city, addr->district, addr->postal_code);
541 if(addr) location_address_free(addr);
542 if(acc) location_accuracy_free(acc);
543 }else if(0 == g_strcmp0("4a",strOpt) ){
544 IdleData* data = g_new0(IdleData, 1);
546 data->addr_cb = cb_address;
547 data->user_data = map_obj;
549 g_printf("[0].San jose [1].Suwon HQ [*].Custom\n");
550 g_printf("Select Position: ");
551 int opt = PromptInt();
552 if(opt == 0) data->pos = location_position_new(0, 37.335276, -121.890059, 0, LOCATION_STATUS_2D_FIX);
553 else if (opt == 1) data->pos = location_position_new(0, 37.257809, 127.056383, 0, LOCATION_STATUS_2D_FIX);
555 g_printf("Input latitude: ");
556 gdouble lat = PromptDB();
557 g_printf("Input longitude: ");
558 gdouble lon = PromptDB();
559 data->pos = location_position_new(0, lat, lon, 0, LOCATION_STATUS_2D_FIX);
561 g_idle_add((GSourceFunc)idle_address_from_position_async, data);
562 }else if(0 == g_strcmp0("5", strOpt)) {
563 g_printf("location_map_search_poi\n");
565 LocationPOIFilter *filter = location_poi_filter_new();
566 location_poi_filter_set(filter, "KEYWORD", "pizza");
568 LocationPOIPreference *pref = location_poi_pref_new();
569 location_poi_pref_set_max_result(pref, 2);
570 location_poi_pref_set_sort_by(pref, "Distance");
571 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_DESC);
573 LocationPosition *position = location_position_new(0, 37.771008, -122.41175, 0, LOCATION_STATUS_2D_FIX);
575 ret = location_map_search_poi(map_obj, filter, position, pref, cb_poi, NULL, &req_id);
576 GetLocationError(str, ret);
577 if(ret != LOCATION_ERROR_NONE) {
578 g_printf("Fail to search POI. Error[%s]\n", str);
580 g_printf("Seach POI success, req_id %d\n", req_id);
583 location_poi_filter_free(filter);
584 location_poi_pref_free(pref);
585 location_position_free(position);
586 }else if(0 == g_strcmp0("5a", strOpt)) {
587 g_printf("location_map_search_poi_with_category\n");
588 LocationPOIFilter *filter = location_poi_filter_new();
589 location_poi_filter_set(filter, "CATEGORY", "restaurant");
591 LocationPOIPreference *pref = location_poi_pref_new();
592 location_poi_pref_set_max_result(pref, 5);
593 location_poi_pref_set_sort_by(pref, "Distance");
594 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC);
596 LocationPosition *position = location_position_new(0, 37.771008, -122.41175, 0, LOCATION_STATUS_2D_FIX);
598 ret = location_map_search_poi(map_obj, filter, position, pref, cb_poi, NULL, &req_id);
599 GetLocationError(str, ret);
600 if(ret != LOCATION_ERROR_NONE) {
601 g_printf("Fail to search POI. Error[%s]\n", str);
603 g_printf("Seach POI success, req_id %d\n", req_id);
606 location_poi_filter_free(filter);g_printf("location_search_poi_by_freeformed_address_with_poi_name\n");
607 location_poi_pref_free(pref);
608 location_position_free(position);
610 }else if(0 == g_strcmp0("5b", strOpt)) {
611 g_printf("location_map_search_poi_with_poi_name\n");
613 LocationPOIFilter *filter = location_poi_filter_new();
614 location_poi_filter_set(filter, "POIName", "cafe");
616 LocationPOIPreference *pref = location_poi_pref_new();
617 location_poi_pref_set_max_result(pref, 10);
618 gchar *item = g_strdup("Distance");
619 location_poi_pref_set_sort_by(pref, item);
620 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_DESC);
622 LocationPosition *position = location_position_new(0, 37.771008, -122.41175, 0, LOCATION_STATUS_2D_FIX);
624 ret = location_map_search_poi(map_obj, filter, position, pref, cb_poi, NULL, &req_id);
625 GetLocationError(str, ret);
626 if(ret != LOCATION_ERROR_NONE) {
627 g_printf("Fail to search POI. Error[%s]\n", str);
629 g_printf("Seach POI success, req_id %d\n", req_id);
632 location_poi_filter_free(filter);
633 location_poi_pref_free(pref);
634 location_position_free(position);
636 }else if(0 == g_strcmp0("6", strOpt)) {
637 g_printf("location_map_search_poi_by_area_with_keyword\n");
639 // only circle supported by decarta
640 LocationPosition *center = location_position_new(0, 37.336723, -121.889555, 0, LOCATION_STATUS_2D_FIX);
641 gdouble radius = 400;
642 LocationBoundary *bound = location_boundary_new_for_circle(center, radius);
644 LocationPOIFilter *filter = location_poi_filter_new();
645 gchar *key = g_strdup("KEYWORD");
646 gchar *value = g_strdup("cafe");
647 location_poi_filter_set(filter, key, value); // same with Type ? CATEGORY, KEYWORD, POIName
649 LocationPOIPreference *pref = location_poi_pref_new();
650 location_poi_pref_set_max_result(pref, 10);
651 gchar *item = g_strdup("Distance");
652 location_poi_pref_set_sort_by(pref, item); // can't set const char* directly !!
653 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); //LOCATION_POI_PREF_SO_ASC
656 ret = location_map_search_poi_by_area(map_obj, filter, bound, pref, cb_poi, NULL, &req_id);
657 GetLocationError(str, ret);
658 if (ret != LOCATION_ERROR_NONE) {
659 g_printf("Fail to search POI by area. Error[%s]\n", str);
661 g_printf("Seach POI by area sucess, req_id %d\n", req_id);
667 location_position_free(center);
668 location_boundary_free(bound);
669 location_poi_filter_free(filter);
670 location_poi_pref_free(pref);
671 }else if(0 == g_strcmp0("6a", strOpt)) {
672 g_printf("location_map_search_poi_by_area_with_category\n");
674 // only circle supported by decarta
675 LocationPosition *center = location_position_new(0, 37.336723, -121.889555, 0, LOCATION_STATUS_2D_FIX);
676 gdouble radius = 400;
677 LocationBoundary *bound = location_boundary_new_for_circle(center, radius);
679 LocationPOIFilter *filter = location_poi_filter_new();
680 gchar *key = g_strdup("CATEGORY");
681 gchar *value = g_strdup("restaurant");
682 location_poi_filter_set(filter, key, value);
684 LocationPOIPreference *pref = location_poi_pref_new();
685 location_poi_pref_set_max_result(pref, 5);
686 gchar *item = g_strdup("Distance");
687 location_poi_pref_set_sort_by(pref, item);
688 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC);
690 ret = location_map_search_poi_by_area(map_obj, filter, bound, pref, cb_poi, NULL, &req_id);
691 GetLocationError(str, ret);
692 if (ret != LOCATION_ERROR_NONE) {
693 g_printf("Fail to search POI by area. Error[%s]\n", str);
695 g_printf("Seach POI by area sucess, req_id %d\n", req_id);
701 location_position_free(center);
702 location_boundary_free(bound);
703 location_poi_filter_free(filter);
704 location_poi_pref_free(pref);
706 }else if(0 == g_strcmp0("6b", strOpt)) {
707 g_printf("location_map_search_poi_by_area_with_poi_name\n");
709 // only circle supported by decarta
710 LocationPosition *center = location_position_new(0, 37.336723, -121.889555, 0, LOCATION_STATUS_2D_FIX);
711 gdouble radius = 400;
712 LocationBoundary *bound = location_boundary_new_for_circle(center, radius);
714 LocationPOIFilter *filter = location_poi_filter_new();
715 gchar *key = g_strdup("POIName");
716 gchar *value = g_strdup("cafe");
717 location_poi_filter_set(filter, key, value); // same with Type ? CATEGORY, KEYWORD, POIName
719 LocationPOIPreference *pref = location_poi_pref_new();
720 location_poi_pref_set_max_result(pref, 10);
721 gchar *item = g_strdup("Distance");
722 location_poi_pref_set_sort_by(pref, item); // can't set const char* directly !!
723 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); //LOCATION_POI_PREF_SO_ASC
726 ret = location_map_search_poi_by_area(map_obj, filter, bound, pref, cb_poi, NULL, &req_id);
727 GetLocationError(str, ret);
728 if (ret != LOCATION_ERROR_NONE) {
729 g_printf("Fail to search POI by area. Error[%s]\n", str);
731 g_printf("Seach POI by area sucess, req_id %d\n", req_id);
737 location_position_free(center);
738 location_boundary_free(bound);
739 location_poi_filter_free(filter);
740 location_poi_pref_free(pref);
742 }else if(0 == g_strcmp0("7", strOpt)) {
743 g_printf("location_map_search_poi_by_address_with_keyword\n");
745 LocationAddress *addr = location_address_new("51", "N SAN PEDRO ST", NULL, "SAN JOSE", "SANTA CLARA", "CA", "95110");
747 LocationPOIFilter *filter = location_poi_filter_new();
748 gchar *key = g_strdup("KEYWORD");
749 gchar *value = g_strdup("cafe");
750 location_poi_filter_set(filter, key, value);
752 LocationPOIPreference *pref = location_poi_pref_new();
753 location_poi_pref_set_max_result(pref, 10);
754 gchar *item = g_strdup("Distance");
755 location_poi_pref_set_sort_by(pref, item);
756 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC);
758 ret = location_map_search_poi_by_address(map_obj, filter, addr, pref, cb_poi, NULL, &req_id);
759 GetLocationError(str, ret);
760 if(ret != LOCATION_ERROR_NONE) {
761 g_printf("Fail to search POI by address. Error[%s]\n", str);
763 g_printf("Seach POI by address sucess, req_id %d\n", req_id);
770 location_address_free(addr);
771 location_poi_filter_free(filter);
772 location_poi_pref_free(pref);
773 }else if(0 == g_strcmp0("7a", strOpt)) {
774 g_printf("location_search_poi_by_address_with_category\n");
776 LocationAddress *addr = location_address_new("51", "N SAN PEDRO ST", NULL, "SAN JOSE", "SANTA CLARA", "CA", "95110");
778 LocationPOIFilter *filter = location_poi_filter_new();
779 location_poi_filter_set(filter, "CATEGORY", "restaurant");
781 LocationPOIPreference *pref = location_poi_pref_new();
782 location_poi_pref_set_max_result(pref, 10);
783 location_poi_pref_set_sort_by(pref, "Distance");
784 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC);
786 ret = location_map_search_poi_by_address(map_obj, filter, addr, pref, cb_poi, NULL, &req_id);
787 GetLocationError(str, ret);
788 if(ret != LOCATION_ERROR_NONE) {
789 g_printf("Fail to search POI by address. Error[%s]\n", str);
791 g_printf("Seach POI by address sucess, req_id %d\n", req_id);
794 location_address_free(addr);
795 location_poi_filter_free(filter);
796 location_poi_pref_free(pref);
797 }else if(0 == g_strcmp0("7b", strOpt)) {
798 g_printf("location_map_search_poi_by_address_with_poi_name\n");
800 LocationAddress *addr = location_address_new("51", "N SAN PEDRO ST", NULL, "SAN JOSE", "SANTA CLARA", "CA", "95110");
802 LocationPOIFilter *filter = location_poi_filter_new();
803 gchar *key = g_strdup("POIName");
804 gchar *value = g_strdup("cafe");
805 location_poi_filter_set(filter, key, value);
807 LocationPOIPreference *pref = location_poi_pref_new();
808 location_poi_pref_set_max_result(pref, 10);
809 gchar *item = g_strdup("Distance");
810 location_poi_pref_set_sort_by(pref, item);
811 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC);
813 ret = location_map_search_poi_by_address(map_obj, filter, addr, pref, cb_poi, NULL, &req_id);
814 GetLocationError(str, ret);
815 if(ret != LOCATION_ERROR_NONE) {
816 g_printf("Fail to search POI by address. Error[%s]\n", str);
818 g_printf("Seach POI by address sucess, req_id %d\n", req_id);
825 location_address_free(addr);
826 location_poi_filter_free(filter);
827 location_poi_pref_free(pref);
829 }else if(0 == g_strcmp0("8", strOpt)) {
830 g_printf("location_map_search_poi_by_freeformed_address_with_keyword\n");
832 gchar *addr = g_strdup("North Second St.");
834 LocationPOIFilter *filter = location_poi_filter_new();
835 location_poi_filter_set(filter, "KEYWORD", "station");
837 LocationPOIPreference *pref = location_poi_pref_new();
838 location_poi_pref_set_max_result(pref, 10);
839 gchar *item = g_strdup("Distance");
840 location_poi_pref_set_sort_by(pref, item); // can't set const char* directly !!
841 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); //LOCATION_POI_PREF_SO_ASC
843 ret = location_map_search_poi_by_freeformed_address(map_obj, filter, addr, pref, cb_poi, NULL, &req_id);
844 GetLocationError(str, ret);
845 if (ret != LOCATION_ERROR_NONE) {
846 g_printf("Fail to search POI by address. Error[%s]\n", str);
848 g_printf("Seach POI by address success, req_id %d\n", req_id);
854 location_poi_filter_free(filter);
855 location_poi_pref_free(pref);
856 }else if(0 == g_strcmp0("8a", strOpt)) {
857 g_printf("location_map_search_poi_by_freeformed_address_with_category\n");
859 gchar *addr = g_strdup("North Second St.");
861 LocationPOIFilter *filter = location_poi_filter_new();
862 gchar *key = g_strdup("CATEGORY");
863 gchar *value = g_strdup("restaurant");
864 location_poi_filter_set(filter, key, value);
866 LocationPOIPreference *pref = location_poi_pref_new();
867 location_poi_pref_set_max_result(pref, 10);
868 gchar *item = g_strdup("Distance");
869 location_poi_pref_set_sort_by(pref, item);
870 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC);
872 ret = location_map_search_poi_by_freeformed_address(map_obj, filter, addr, pref, cb_poi, NULL, &req_id);
873 GetLocationError(str, ret);
874 if (ret != LOCATION_ERROR_NONE) {
875 g_printf("Fail to search POI by address. Error[%s]\n", str);
877 g_printf("Seach POI by address success, req_id %d\n", req_id);
885 location_poi_filter_free(filter);
886 location_poi_pref_free(pref);
887 }else if(0 == g_strcmp0("8b", strOpt)) {
888 g_printf("location_map_search_poi_by_freeformed_address_with_poi_name\n");
890 gchar *addr = g_strdup("North Second St.");
892 LocationPOIFilter *filter = location_poi_filter_new();
893 location_poi_filter_set(filter, "POIName", "pizza");
895 LocationPOIPreference *pref = location_poi_pref_new();
896 location_poi_pref_set_max_result(pref, 10);
897 location_poi_pref_set_sort_by(pref, "Distance");
898 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC);
900 ret = location_map_search_poi_by_freeformed_address(map_obj, filter, addr, pref, cb_poi, NULL, &req_id);
901 GetLocationError(str, ret);
902 if (ret != LOCATION_ERROR_NONE) {
903 g_printf("Fail to search POI by address. Error[%s]\n", str);
905 g_printf("Seach POI by address success, req_id %d\n", req_id);
909 location_poi_filter_free(filter);
910 location_poi_pref_free(pref);
912 }else if(0 == g_strcmp0("9", strOpt)) {
915 g_printf("Input ReqID : ");
916 scanf("%d", &req_id);
918 ret = location_map_cancel_poi_request(map_obj, req_id);
919 GetLocationError(str, ret);
920 if (ret != LOCATION_ERROR_NONE) {
921 g_printf("Fail to cancel POI request. Error[%s]\n", str);
924 g_printf("location_map_cancel_poi_request, req_id %d\n", req_id);
925 }else if(0 == g_strcmp0("10", strOpt)) {
926 g_printf("location_map_request_route\n\n");
928 LocationPosition *origin = location_position_new(0, 37.564263, 126.974676, 0, LOCATION_STATUS_2D_FIX); // Seoul city hall
929 LocationPosition *destination = location_position_new(0, 37.557120, 126.992410, 0, LOCATION_STATUS_2D_FIX); // NamSan
931 GList *waypoint = NULL;
932 LocationPosition *via_pos = location_position_new(0, 37.560950, 126.986240, 0, LOCATION_STATUS_2D_FIX); // Wangsimli
933 waypoint = g_list_append (waypoint, (gpointer)via_pos);
935 LocationRoutePreference *pref = location_route_pref_new();
936 location_route_pref_set_route_type(pref, "FASTEST");
938 ret = location_map_request_route(map_obj, origin, destination, waypoint, pref, cb_route, NULL, &req_id);
939 GetLocationError(str, ret);
940 if (ret != LOCATION_ERROR_NONE) {
941 g_printf("Fail to search route by address. Error[%s]\n", str);
943 g_printf("Search Route successfully, req_id %d\n", req_id);
945 }else if(0 == g_strcmp0("10a", strOpt)) {
946 g_printf("location_map_request_route for a long distance\n");
948 LocationPosition *origin = location_position_new(0, 29.783449,-95.373688, 0, LOCATION_STATUS_2D_FIX);
949 LocationPosition *destination = location_position_new(0, 39.749962,-104.984665, 0, LOCATION_STATUS_2D_FIX);
951 GList *waypoint = NULL;
953 LocationRoutePreference *pref = location_route_pref_new();
954 location_route_pref_set_route_type(pref, "FASTEST");
956 ret = location_map_request_route(map_obj, origin, destination, waypoint, pref, cb_route, NULL, &req_id);
957 GetLocationError(str, ret);
958 if (ret != LOCATION_ERROR_NONE) {
959 g_printf("Fail to search route by address. Error[%s]\n", str);
961 g_printf("Search Route successfully, req_id %d\n", req_id);
965 }else if(0 == g_strcmp0("11", strOpt)) {
966 g_printf("location_map_cancel_route_request\n");
969 g_printf("Input ReqID : ");
970 scanf("%d", &req_id);
972 ret = location_map_cancel_route_request(map_obj, req_id);
973 GetLocationError(str, ret);
974 if (ret != LOCATION_ERROR_NONE) {
975 g_printf("Fail to cancel route request. Error[%s]\n", str);
978 g_printf("location_map_cancel_route_request, req_id %d\n", req_id);
981 }else if (0 == g_strcmp0 ("12", strOpt)) {
983 for (idx = 0; idx < MAP_SERVICE_TYPE_MAX; idx++) {
984 g_printf("[%d:%d], ", idx, location_map_is_supported_provider_capability (map_obj, idx));
986 }else if (0 == g_strcmp0 ("13", strOpt)) {
988 for (idx = 0; idx < MAP_SERVICE_TYPE_MAX; idx++) {
989 g_printf("[%d:", idx);
990 print_map_service_keys(map_obj, idx);
993 }else if (0 == g_strcmp0 ("14", strOpt)) {
994 GList *list = location_map_get_supported_providers (map_obj);
996 g_list_foreach (list, _print_provider, NULL);
997 g_list_free_full (list, g_free);
1000 g_printf("Fail to get supported_providers\n");
1002 }else if (0 == g_strcmp0 ("15", strOpt)) {
1003 gchar *default_provider = location_map_get_default_provider (map_obj);
1004 if (default_provider) {
1005 g_printf("Defaut : [%s]\n", default_provider);
1006 g_free (default_provider);
1009 g_printf("Fail to get default provider\n");
1011 }else if (0 == g_strcmp0 ("16", strOpt)) {
1012 g_printf("[0].default [1].decarta [2].osm\n");
1013 g_printf("Select provider: ");
1014 int opt = PromptInt();
1015 gboolean ret = FALSE;
1019 ret = location_map_set_provider (map_obj, NULL);
1022 ret = location_map_set_provider (map_obj, "decarta");
1025 ret = location_map_set_provider (map_obj, "osm");
1032 g_printf ("Success to set provider [%d]\n", opt);
1035 g_printf ("Fail to set provider [%d]\n", opt);
1037 }else if (0 == g_strcmp0 ("99", strOpt)) {
1039 g_object_set (map_obj, "provider", NULL, NULL);
1041 }else if (0 == g_strcmp0 ("99a", strOpt)) {
1043 g_object_set (map_obj, "provider", "decarta", NULL);
1045 }else if (0 == g_strcmp0 ("99b", strOpt)) {
1047 g_object_set (map_obj, "provider", "osm", NULL);
1049 }else if(0 == g_strcmp0("q",strOpt) ){
1050 g_main_loop_quit(g_mainloop);
1054 g_thread_join(g_main);
1055 g_printf("\n--- Exit LBS Test App ---\n");