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>
27 #include <location-map-service.h>
28 #include <location-poi.h>
29 #include "location-api-test-util.h"
32 LocationObject* location_obj = NULL;
33 static GMainLoop *g_mainloop = NULL;
35 #define LOCATION_API_TEST_JSON_FILE "/opt/data/location-api-test.json"
37 static gpointer GmainThread(gpointer data)
39 g_mainloop = g_main_loop_new (NULL, FALSE);
40 g_printf("\n...Entering GMain Loop to Receive Notifications....\n");
41 g_main_loop_run (g_mainloop);
42 g_main_loop_unref (g_mainloop);
48 static void GetLocationError(char str[STR_MAX], int ret)
52 case LOCATION_ERROR_NONE:
53 g_utf8_strncpy(str, "LOCATION_ERROR_NONE", STR_MAX);
55 case LOCATION_ERROR_NOT_ALLOWED:
56 g_utf8_strncpy(str, "LOCATION_ERROR_NOT_ALLOWED", STR_MAX);
58 case LOCATION_ERROR_NOT_AVAILABLE:
59 g_utf8_strncpy(str, "LOCATION_ERROR_NOT_AVAILABLE", STR_MAX);
61 case LOCATION_ERROR_NETWORK_FAILED:
62 g_utf8_strncpy(str, "LOCATION_ERROR_NETWORK_FAILED", STR_MAX);
64 case LOCATION_ERROR_NETWORK_NOT_CONNECTED:
65 g_utf8_strncpy(str, "LOCATION_ERROR_NETWORK_NOT_CONNECTED", STR_MAX);
67 case LOCATION_ERROR_CONFIGURATION:
68 g_utf8_strncpy(str, "LOCATION_ERROR_CONFIGURATION", STR_MAX);
70 case LOCATION_ERROR_PARAMETER:
71 g_utf8_strncpy(str, "LOCATION_ERROR_PARAMETER", STR_MAX);
73 case LOCATION_ERROR_UNKNOWN:
74 g_utf8_strncpy(str, "LOCATION_ERROR_UNKNOWN", STR_MAX);
77 g_utf8_strncpy(str, "Error: undefined error code", STR_MAX);
81 static void GetStatus(char str[STR_MAX], LocationStatus acc_level)
85 case LOCATION_STATUS_NO_FIX:
86 g_utf8_strncpy(str, "LOCATION_STATUS_NO_FIX", STR_MAX);
88 case LOCATION_STATUS_2D_FIX:
89 g_utf8_strncpy(str, "LOCATION_STATUS_2D_FIX", STR_MAX);
91 case LOCATION_STATUS_3D_FIX:
92 g_utf8_strncpy(str, "LOCATION_STATUS_3D_FIX", STR_MAX);
95 g_utf8_strncpy(str, "Error: undefined status code", STR_MAX);
99 static void GetMethod(char str[STR_MAX], LocationMethod acc_level)
103 case LOCATION_METHOD_HYBRID:
104 g_utf8_strncpy(str, "LOCATION_METHOD_HYBRID", STR_MAX);
106 case LOCATION_METHOD_GPS:
107 g_utf8_strncpy(str, "LOCATION_METHOD_GPS", STR_MAX);
109 case LOCATION_METHOD_CPS:
110 g_utf8_strncpy(str, "LOCATION_METHOD_CPS", STR_MAX);
112 case LOCATION_METHOD_IPS:
113 g_utf8_strncpy(str, "LOCATION_METHOD_IPS", STR_MAX);
115 case LOCATION_METHOD_WPS:
116 g_utf8_strncpy(str, "LOCATION_METHOD_WPS", STR_MAX);
118 case LOCATION_METHOD_SPS:
119 g_utf8_strncpy(str, "LOCATION_METHOD_SPS", STR_MAX);
122 g_utf8_strncpy(str, "Error: undefined method", STR_MAX);
126 static void GetAccuracyLevel(char str[STR_MAX], LocationAccuracyLevel acc_level)
130 case LOCATION_ACCURACY_LEVEL_NONE:
131 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_NONE", STR_MAX);
133 case LOCATION_ACCURACY_LEVEL_COUNTRY:
134 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_COUNTRY", STR_MAX);
136 case LOCATION_ACCURACY_LEVEL_REGION:
137 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_REGION", STR_MAX);
139 case LOCATION_ACCURACY_LEVEL_LOCALITY:
140 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_LOCALITY", STR_MAX);
142 case LOCATION_ACCURACY_LEVEL_POSTALCODE:
143 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_POSTALCODE", STR_MAX);
145 case LOCATION_ACCURACY_LEVEL_STREET:
146 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_STREET", STR_MAX);
148 case LOCATION_ACCURACY_LEVEL_DETAILED:
149 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_DETAILED", STR_MAX);
152 g_utf8_strncpy(str, "Error: undefined accuracy level", STR_MAX);
157 static void SelectOpt(char* buf)
160 fgets(buf, 255, stdin);
161 iLen = g_utf8_strlen(buf, -1);
165 static int PromptInt()
169 fgets(buf, 255, stdin);
170 buf[strlen(buf)-1]='\0';
171 ret = g_ascii_strtoll(buf, NULL, 10);
175 static double PromptDB()
179 fgets(buf, 255, stdin);
180 buf[strlen(buf)-1]='\0';
181 ret = g_ascii_strtod(buf, NULL);
185 static void PrintPos (gpointer data, gpointer user_data)
187 LocationPosition *pos = (LocationPosition *)data;
189 g_printf("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
190 location_position_free (pos);
194 static void PrintAcc (gpointer data, gpointer user_data)
196 LocationAccuracy *acc = (LocationAccuracy *)data;
198 g_printf("level: [%d], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
199 location_accuracy_free (acc);
204 gulong g_sig_enable = 0;
205 gulong g_sig_disable = 0;
206 gulong g_sig_update = 0;
207 gulong g_sig_zonein = 0;
208 gulong g_sig_zoneout = 0;
210 static void PrintPolygonPosition(gpointer data, gpointer user_data)
212 LocationPosition *position = (LocationPosition*) data;
213 g_printf("[%lf %lf %lf] ", position->latitude, position->longitude, position->altitude);
216 static void PrintBoundary(LocationBoundary *boundary, void *user_data)
218 if(boundary == NULL) return;
219 if (boundary->type == LOCATION_BOUNDARY_CIRCLE) {
220 g_printf("\n\tCIRCLE: center[%lf %lf %lf] radius[%lf]",
221 boundary->circle.center->latitude, boundary->circle.center->longitude, boundary->circle.center->altitude, boundary->circle.radius);
222 } else if (boundary->type == LOCATION_BOUNDARY_RECT) {
223 g_printf("\n\tRECT: left_top[%lf %lf %lf] right_bottom[%lf %lf %lf]",
224 boundary->rect.left_top->latitude, boundary->rect.left_top->longitude, boundary->rect.left_top->altitude,
225 boundary->rect.right_bottom->latitude, boundary->rect.right_bottom->longitude, boundary->rect.right_bottom->altitude);
226 } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) {
227 g_printf("\n\tPOLYGON: ");
229 GList *list = boundary->polygon.position_list;
231 g_list_foreach(list, PrintPolygonPosition, NULL);
235 static void RemoveBoundary(LocationBoundary *boundary, void *user_data)
237 LocationObject * obj = (LocationObject *)user_data;
238 if(obj == NULL || boundary == NULL) return;
240 location_boundary_remove(obj, boundary);
243 static void PrintProperty (LocationObject* loc)
246 LocationMethod method = LOCATION_METHOD_NONE;
247 LocationPosition *pos = NULL;
249 gchar method_str[STR_MAX] = {0, };
250 gchar status_str[STR_MAX] = {0, };
252 gchar* devname = NULL;
254 g_object_get(loc, "method", &method, NULL);
255 GetMethod(method_str, method);
256 g_printf("method[%s] ", method_str);
258 if (LOCATION_METHOD_GPS == method) {
259 g_object_get(loc, "dev-name", &devname, NULL);
261 g_printf("dev-name[%s] ", devname);
266 g_object_get(loc, "last-position", &pos, NULL);
268 GetStatus(status_str, pos->status);
269 g_printf("\nLast position [time(%d) lat(%f) long(%f) alt(%f) status(%s)]",
270 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, status_str);
271 location_position_free (pos);
274 g_object_get(loc, "update-interval", &interval, NULL);
275 g_printf("Update interval : [%u]", interval);
277 if (LOCATION_METHOD_CPS == method || LOCATION_METHOD_IPS == method) return;
279 g_printf("\nSignals: ");
280 if (g_sig_enable) g_printf("[service-enabled], ");
281 if (g_sig_disable) g_printf("[service-disabled], ");
282 if (g_sig_update) g_printf("[service-updated], ");
283 if (g_sig_zonein) g_printf("[zone-in], ");
284 if (g_sig_zoneout) g_printf("[zone-out]");
287 static void cb_service_enabled (GObject *self, guint status, gpointer userdata)
289 g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
291 LocationObject *loc = (LocationObject*)userdata;
292 LocationAccuracy *acc = NULL;
293 LocationPosition *pos = NULL;
294 LocationVelocity *vel = NULL;
295 LocationAddress *addr = NULL;
296 LocationMethod method;
298 g_object_get(loc, "method", &method, NULL);
299 g_debug("Get property>> method:%d", method);
301 if (LOCATION_ERROR_NONE == location_get_position (loc, &pos, &acc)) {
302 g_debug ("SYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
303 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
304 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
305 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
306 location_position_free(pos);
307 location_accuracy_free(acc);
308 } else g_warning ("SYNC>> Current position> failed");
309 if (LOCATION_ERROR_NONE == location_get_velocity (loc, &vel, &acc)) {
310 g_debug ("SYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f",
311 vel->timestamp, vel->speed, vel->direction, vel->climb);
312 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
313 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
314 location_velocity_free(vel);
315 location_accuracy_free(acc);
316 } else g_warning ("SYNC>> Current velocity> failed");
317 if (LOCATION_ERROR_NONE == location_get_address(loc, &addr, &acc)) {
318 g_debug ("SYNC>> Current address> %s %s %s %s %s %s %s",
319 addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code);
320 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
321 location_address_free(addr);
322 location_accuracy_free(acc);
323 } else g_warning ("SYNC>> Current address> failed");
327 cb_service_disabled (GObject *self,
331 g_debug("cb_service_disabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
335 cb_zone_in (GObject *self,
340 g_debug("cb_zone_in: type(%d)", type);
341 LocationPosition *pos = (LocationPosition*) position;
342 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
344 g_debug ("ASYNC>> ZoneIn> Current position: time: %d, lat: %f, long: %f, alt: %f",
345 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
346 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
347 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
351 cb_zone_out (GObject *self,
356 g_debug("cb_zone_out: type(%d)", type);
357 LocationPosition *pos = (LocationPosition*) position;
358 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
360 g_debug ("ASYNC>> ZoneOut> Current position: time: %d, lat: %f, long: %f, alt: %f",
361 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
362 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
363 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
367 cb_service_updated (GObject *self,
373 g_debug("cb_service_updated: type(%d) userdata(0x%x)", type, (unsigned int)userdata);
375 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
377 case POSITION_UPDATED: {
378 LocationPosition *pos = (LocationPosition*) data;
379 g_debug ("ASYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
380 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
381 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
382 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
385 case VELOCITY_UPDATED: {
386 LocationVelocity *vel = (LocationVelocity*) data;
387 g_debug ("ASYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f",
388 vel->timestamp, vel->speed, vel->direction, vel->climb);
389 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
390 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
393 case SATELLITE_UPDATED: {
401 LocationSatellite *sat = (LocationSatellite *)data;
402 g_debug ("SYNC>> Current Satellite> time: %d, satellite in view = %d, satellite in used = %d", sat->timestamp, sat->num_of_sat_inview, sat->num_of_sat_used);
403 g_debug ("\tinview satellite information = ");
404 for (idx=0; idx<sat->num_of_sat_inview; idx++) {
405 location_satellite_get_satellite_details(sat, idx, &prn, &used, &elevation, &azimuth, &snr);
406 g_debug ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d", idx, used, prn, elevation, azimuth, snr);
411 g_warning ("ASYNC>> Undefined update type");
416 static void _print_property (gpointer data, gpointer user_data)
418 LocationLandmark *landmark = (LocationLandmark *)user_data;
419 gpointer key = (gpointer)data;
420 gpointer value = NULL;
423 value = (gpointer)location_landmark_get_property(landmark, key);
424 g_printf(", [%s:%s]", (gchar*) key, (gchar*) value);
429 __plugin_print_poi_list (gpointer data, gpointer user_data)
431 LocationLandmark *landmark = (LocationLandmark *)data;
432 LocationPosition *pos = location_landmark_get_position (landmark);
433 LocationAddress *addr = location_landmark_get_address (landmark);
435 g_printf ("[ID:%d], [NAME:%s], phone[%s],pos[%f:%f], addr[%s:%s:%s:%s:%s]",
436 location_landmark_get_id (landmark),
437 location_landmark_get_name(landmark),
438 location_landmark_get_phone_number (landmark),
439 pos->latitude, pos->longitude,
440 addr->building_number, addr->city, addr->country_code, addr->district,
443 GList *key_list = location_landmark_get_property_key(landmark);
445 g_list_foreach(key_list, _print_property, landmark);
452 static void cb_poi(LocationError error, guint req_id, GList * landmark_list, gchar * error_code, gchar * error_msg, gpointer userdata)
454 g_printf("\n===== __location_POI_cb ======\n");
455 if (error != LOCATION_ERROR_NONE) {
456 g_printf("Failed :%d\n", error);
459 g_printf("Success, poi_list[0x%x] user_data[0x%x] req_id[%d]\n", (unsigned int)landmark_list, (unsigned int)userdata, req_id);
460 g_list_foreach (landmark_list, __plugin_print_poi_list, NULL);
462 if (error_code && error_msg) {
463 g_printf("__location_POI_cb: error_code[%s], error_msg[%s]\n", error_code, error_msg);
466 static void PrintStepInfo(const LocationRouteStep *step)
468 const LocationPosition *start = location_route_step_get_start_point(step);
469 gdouble start_lat = 0;
470 gdouble start_lon = 0;
472 start_lat = start->latitude;
473 start_lon = start->longitude;
475 g_printf("Step start position NULL\n");
477 const LocationPosition *end = location_route_step_get_end_point(step);
481 end_lat = end->latitude;
482 end_lon = end->longitude;
484 g_printf("Step end position NULL\n");
486 const gchar *inst = location_route_step_get_instruction(step);
488 g_printf("Step: start(%f/%f), end(%f/%f), instruction(%s)\n", start_lat, start_lon, end_lat, end_lon, inst);
491 static void cb_print_route_step (gpointer data, gpointer user_data)
493 g_printf("+++Step begin\n");
494 LocationRouteStep *step = (LocationRouteStep *)data;
497 g_printf("---Step end\n");
500 static void cb_print_route_segment (gpointer data, gpointer user_data)
502 g_printf("++Segment begin\n");
503 LocationRouteSegment *seg = (LocationRouteSegment *)data;
504 gdouble seg_dist = location_route_segment_get_distance(seg);
505 glong seg_duration = location_route_segment_get_duration(seg);
506 const LocationPosition *start = location_route_segment_get_start_point(seg);
507 gdouble start_lat = 0;
508 gdouble start_lon = 0;
510 start_lat = start->latitude;
511 start_lon = start->longitude;
513 g_printf("Segment start position NULL\n");
515 const LocationPosition *end = location_route_segment_get_end_point(seg);
519 end_lat = end->latitude;
520 end_lon = end->longitude;
522 g_printf("Segment end postion NULL\n");
524 g_printf("Segment info: Distance[%f], Duration[%ld], start(%f/%f), end(%f/%f)\n", seg_dist, seg_duration,
525 start_lat, start_lon, end_lat, end_lon);
527 GList *step_list = location_route_segment_get_route_step(seg);
528 GList *tmp_list = (GList *)step_list;
530 g_list_foreach(tmp_list, cb_print_route_step, NULL);
532 g_printf("--Segment end\n");
536 static void cb_print_route_list (gpointer data, gpointer user_data)
538 g_printf("+Route begin\n");
539 LocationRoute *route = (LocationRoute *)data;
541 const LocationPosition *start = location_route_get_origin(route);
542 gdouble start_lat = 0;
543 gdouble start_lon = 0;
545 start_lat = start->latitude;
546 start_lon = start->longitude;
548 g_printf("Route start position NULL\n");
550 const LocationPosition *end = location_route_get_destination(route);
554 end_lat = end->latitude;
555 end_lon = end->longitude;
557 g_printf("Route end position NULL\n");
559 g_printf("Route: start(%f/%f), end(%f/%f)\n", start_lat, start_lon, end_lat, end_lon);
561 gdouble distance = location_route_get_total_distance(route);
562 const gchar *dis_unit = location_route_get_distance_unit(route);
563 glong duration = location_route_get_total_duration(route);
564 const LocationBoundary *bound = location_route_get_bounding_box(route);
565 if (bound && bound->type == LOCATION_BOUNDARY_RECT) {
566 g_printf("RECT left top[%f-%f], right bottom[%f-%f]\n", bound->rect.left_top->latitude, bound->rect.left_top->longitude,
567 bound->rect.right_bottom->latitude, bound->rect.right_bottom->longitude);
569 g_printf("route boundary not exist, or not RECT\n");
571 g_printf ("Distance[%f], Distance unit[%s], Duration[%ld]\n", distance, dis_unit, duration);
573 GList *seg_list = location_route_get_route_segment(route);
575 g_list_foreach(seg_list, cb_print_route_segment, NULL);
578 g_printf("-Route end\n");
581 static void cb_route(LocationError error, guint req_id, GList * route_list, gchar * error_code, gchar * error_msg, gpointer userdata)
583 g_printf("\n===== cb_route ======\n");
584 if (error != LOCATION_ERROR_NONE) {
585 g_printf("Failed :%d\n", error);
589 g_printf("Success, poi_list[0x%x] user_data[0x%x] req_id[%d]\n", (unsigned int)route_list, (unsigned int)userdata, req_id);
590 g_list_foreach (route_list, cb_print_route_list, NULL);
592 if (error_code && error_msg) {
593 g_printf("cb_route: error_code[%s], error_msg[%s]\n", error_code, error_msg);
597 static void cb_position (LocationError error,
602 if (error != LOCATION_ERROR_NONE) {
603 g_printf("cb_position failed: error=%d\n", error);
607 g_list_foreach (pos_list, PrintPos, NULL);
608 g_list_foreach (acc_list, PrintAcc, NULL);
611 static void cb_address(LocationError error, LocationAddress *addr, LocationAccuracy *acc, gpointer userdata)
613 if (error != LOCATION_ERROR_NONE) {
614 g_printf("cb_address failed: error=%d\n", error);
618 g_printf("userdata[0x%x] building number: [%s], street: [%s], state: [%s], country code: [%s], city: [%s], district: [%s], postal code: [%s]\n",
619 (unsigned int)userdata, addr->building_number, addr->street, addr->state, addr->country_code, addr->city, addr->district, addr->postal_code);
620 GetAccuracyLevel(str, acc->level);
621 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
626 LocationPosition *pos;
627 LocationAddress *addr;
629 LocationPositionCB pos_cb;
630 LocationAddressCB addr_cb;
634 static gboolean idle_position_from_address_async(gpointer data)
636 IdleData* idle_data = (IdleData*)data;
638 int ret = location_get_position_from_address_async(idle_data->obj, idle_data->addr, idle_data->pos_cb, idle_data->user_data);
639 GetLocationError(str, ret);
640 g_printf("location_get_position_from_address_async: returned value [%s]\n", str);
641 location_address_free(idle_data->addr);
646 static gboolean idle_position_from_freefromed_address_async(gpointer data)
648 IdleData* idle_data = (IdleData*)data;
650 int ret = location_get_position_from_freeformed_address_async(idle_data->obj, idle_data->str_addr, idle_data->pos_cb, idle_data->user_data);
651 GetLocationError(str, ret);
652 g_printf("location_get_position_from_freeformed_address_async: returned value [%s]\n", str);
653 g_free(idle_data->str_addr);
658 static gboolean idle_address_async(gpointer data)
660 IdleData* idle_data = (IdleData*)data;
662 int ret = location_get_address_async(idle_data->obj, idle_data->addr_cb, idle_data->user_data);
663 GetLocationError(str, ret);
664 g_printf("location_get_address_async: returned value [%s]\n", str);
669 static gboolean idle_address_from_position_async(gpointer data)
671 IdleData* idle_data = (IdleData*)data;
673 int ret = location_get_address_from_position_async(idle_data->obj, idle_data->pos, idle_data->addr_cb, idle_data->user_data);
674 GetLocationError(str, ret);
675 g_printf("location_get_address_from_position_async: returned value [%s]\n", str);
676 location_position_free(idle_data->pos);
681 void _print_keys(gpointer value)
683 g_printf(" %s ", (gchar*) value);
686 static void print_map_service_keys (LocationObject *obj, int type)
690 int ret = location_get_map_provider_capability_key (obj, type, &key);
693 g_list_foreach (key, _print_keys, NULL);
696 g_list_free_full(key, g_free);
699 static void print_menu()
701 g_printf("\n================================= Location API Test =================================\n");
702 g_printf("q. Exit\n");
703 g_printf("1. location_init\n");
704 g_printf("2. location_new\n");
705 g_printf("3. location_free\n");
706 g_printf("4. location_start\n");
707 g_printf("5. location_stop\n");
708 g_printf("6. location_get_position\n");
709 g_printf("6a. location_get_last_position\n");
710 g_printf("6b. location_get_last_known_position - will be deprecated. \n");
711 g_printf("7. location_get_position_from_address\n");
712 g_printf("7a. location_get_position_from_address_async\n");
713 g_printf("8. location_get_position_from_freeformed_address\n");
714 g_printf("8a. location_get_position_from_freeformed_address_async\n");
715 g_printf("9. location_get_velocity\n");
716 g_printf("9a. location_get_last_velocity\n");
717 g_printf("10. location_get_satellite\n");
718 g_printf("10a. location_get_last_satellite\n");
719 g_printf("11. location_get_address\n");
720 g_printf("11a. location_get_address_async\n");
721 g_printf("12. location_get_address_from_position\n");
722 g_printf("12a. location_get_address_from_position_async\n");
723 g_printf("13. location_get_distance\n");
724 g_printf("14. location_is_supported_method\n");
725 g_printf("15. location_is_enabled_gps\n");
726 g_printf("16. location_search_poi\n");
727 g_printf("16a. location_search_poi_by_area\n");
728 g_printf("16b. location_search_poi_by_addr\n");
729 g_printf("16c. location_search_poi_by_freeformed_address\n");
730 g_printf("16d. location_search_poi_by_area\n");
731 g_printf("16e. location_cancel_poi_request\n");
732 g_printf("17. location_request_route\n");
733 g_printf("17a. location_cancel_route_request\n");
734 g_printf("18. location_is_supported_map_provider_capability\n");
735 g_printf("19. location_get_map_provider_capability_key\n");
736 g_printf("99. location_send_command\n");
737 g_printf("a?. signals:(1)'service-enabled',(2)'service-disabled',(3)'service-updated',(4)'zone-in',(5)'zone-out'\n");
738 g_printf("b?. disconnect signals:(1)'service-enabled',(2)'service-disabled',(3)'service-updated',(4)'zone-in',(5)'zone-out'\n");
739 g_printf("c?. (1)Set boundary, (2)Get boundary, (3) Remove boundary, (4) Remove all boundaries, (5)Set device name, (6)Set update interval\n");
740 g_printf("==================================== Property ====================================\n");
741 PrintProperty(location_obj);
742 g_printf("\n==================================================================================\n");
745 int main(int argc, char** argv)
753 // If application is executed by AUL, this is not needed.
754 g_setenv("PKG_NAME", "com.samsung.location-api-test", 1);
757 if( !g_thread_supported() )
763 g_main = g_thread_create(GmainThread, NULL, TRUE, &gerr);
765 g_debug("Error create gmain thread: Err domain[%d] Err code[%d] Err msg[%s]",
766 gerr->domain, gerr->code, gerr->message);
771 json_util_init(LOCATION_API_TEST_JSON_FILE);
772 g_printf("--- Start LBS Test App ---\n");
776 g_printf("Select option: ");
778 g_printf("======================================================================================\n");
779 if (0 == g_strcmp0 ("x", strOpt)) {
782 else if (0 == g_strcmp0("1",strOpt)) {
783 ret = location_init();
784 GetLocationError(str, ret);
785 g_printf("location_init: returned value [%s]\n", str);
786 } else if (0 == g_strcmp0("2",strOpt)) {
788 g_printf("Location object already existed: [0x%x]", (unsigned int)location_obj);
791 g_printf("LOCATION_METHOD_HYBRID[0] LOCATION_METHOD_GPS[1] LOCATION_METHOD_WPS[2] LOCATION_METHOD_SPS[5]\n");
792 g_printf("Select Location Method: ");
793 LocationMethod method = PromptInt();
794 location_obj = location_new(method);
795 if(location_obj) g_printf("Success\n");
796 else g_printf("Failed\n");
797 } else if (0 == g_strcmp0("3",strOpt)) {
798 ret = location_free (location_obj);
805 GetLocationError(str, ret);
806 g_printf("location_free: returned value [%s]\n", str);
807 } else if (0 == g_strcmp0("4",strOpt)) {
808 ret = location_start(location_obj);
809 GetLocationError(str, ret);
810 g_printf("location_start: returned value [%s]\n", str);
811 } else if (0 == g_strcmp0("5",strOpt)) {
812 ret = location_stop(location_obj);
813 GetLocationError(str, ret);
814 g_printf("location_stop: returned value [%s]\n", str);
815 } else if (0 == g_strcmp0("6",strOpt)) {
816 LocationPosition *pos = NULL;
817 LocationAccuracy *acc = NULL;
818 ret = location_get_position(location_obj, &pos, &acc);
819 GetLocationError(str, ret);
820 g_printf("location_get_position: returned value [%s]\n", str);
821 if (ret == LOCATION_ERROR_NONE) {
822 g_printf("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f], status: [%d]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
823 GetAccuracyLevel(str, acc->level);
824 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
826 if(pos) location_position_free(pos);
827 if(acc) location_accuracy_free(acc);
828 } else if (0 == g_strcmp0("6a",strOpt)) {
829 LocationPosition *last_pos;
830 LocationAccuracy *last_acc;
833 ret = location_get_last_position (location_obj, &last_pos, &last_acc);
834 GetLocationError(str, ret);
835 if (ret == LOCATION_ERROR_NONE) {
836 g_debug ("SYNC>> Last position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
837 last_pos->timestamp, last_pos->latitude, last_pos->longitude, last_pos->altitude, last_pos->status);
838 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
839 last_acc->level, last_acc->horizontal_accuracy, last_acc->vertical_accuracy);
840 location_position_free(last_pos);
841 location_accuracy_free(last_acc);
842 } else g_warning ("SYNC>> Last position> failed. Error[%s]",str);
844 } else if (0 == g_strcmp0("6b",strOpt)) {
845 g_printf("LOCATION_METHOD_HYBRID[0] LOCATION_METHOD_GPS[1] LOCATION_METHOD_WPS[2] LOCATION_METHOD_SPS[5]\n");
846 g_printf("Select Location Method: ");
847 LocationMethod method = PromptInt();
848 LocationLastPosition last_pos;
849 ret = location_get_last_known_position(location_obj, method, &last_pos);
850 GetLocationError(str, ret);
851 g_printf("location_get_last_known_position: returned value [%s]\n", str);
852 if (ret == LOCATION_ERROR_NONE) {
853 g_printf("last position method[%d], latitude: [%f], longitude: [%f], altitude: [%f], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", last_pos.method, last_pos.latitude, last_pos.longitude, last_pos.altitude, last_pos.horizontal_accuracy, last_pos.vertical_accuracy);
855 } else if (0 == g_strcmp0("7",strOpt)) {
856 LocationAddress *add = NULL;
857 GList *pos_list = NULL;
858 GList *acc_list = NULL;
860 g_printf("[0].San jose [1].수원 삼성 [2].Suwon HQ [*].Custom\n");
861 g_printf("Select Address: ");
862 int opt = PromptInt();
863 if (opt == 0) add = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113");
864 else if (opt == 1) add = location_address_new (NULL, "삼성전자", "매탄 3동", "수원시 영통구", "경기도", NULL, NULL);
865 else if (opt == 2) add = location_address_new (NULL, "Samsung Electro-Mechanics Co. LTD", "Maetan 3-dong", "Suwon Si Yeongtong-gu", "Gyeonggi-do", NULL, NULL);
867 char building_number[255], street[255], state[255], country_code[255], city[255], district[255], postal_code[255];
868 g_printf("Input building number: ");
869 fgets(building_number, 255, stdin);
870 building_number[strlen(building_number)-1]='\0';
871 g_printf("Input street: ");
872 fgets(street, 255, stdin);
873 street[strlen(street)-1]='\0';
874 g_printf("Input state: ");
875 fgets(state, 255, stdin);
876 state[strlen(state)-1]='\0';
877 g_printf("Input country code: ");
878 fgets(country_code, 255, stdin);
879 country_code[strlen(country_code)-1]='\0';
880 g_printf("Input city: ");
881 fgets(city, 255, stdin);
882 city[strlen(city)-1]='\0';
883 g_printf("Input district: ");
884 fgets(district, 255, stdin);
885 district[strlen(district)-1]='\0';
886 g_printf("Input postal code: ");
887 fgets(postal_code, 255, stdin);
888 postal_code[strlen(postal_code)-1]='\0';
889 add = location_address_new(building_number, street, district, city, state, country_code, postal_code);
891 ret = location_get_position_from_address (location_obj, add, &pos_list, &acc_list);
892 if(add) location_address_free (add);
893 GetLocationError(str, ret);
894 g_printf("location_get_position_from_adress: returned value [%s]\n", str);
895 if (ret == LOCATION_ERROR_NONE) {
896 g_list_foreach (pos_list, PrintPos, NULL);
897 g_list_foreach (acc_list, PrintAcc, NULL);
899 } else if (0 == g_strcmp0("7a",strOpt)) {
900 IdleData* data = g_new0(IdleData, 1);
901 data->obj = location_obj;
902 data->pos_cb = cb_position;
903 data->user_data = location_obj;
905 g_printf("[0].San jose [1].수원 삼성 [2].Suwon HQ [*].Custom\n");
906 g_printf("Select Address: ");
907 int opt = PromptInt();
908 if (opt == 0) data->addr = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113");
909 else if (opt == 1) data->addr = location_address_new (NULL, "삼성전자", "매탄3동", "수원시 영통구", "경기도", NULL, NULL);
910 else if (opt == 2) data->addr = location_address_new (NULL, "Samsung Electro-Mechanics Co. LTD", "Maetan 3-dong", "Suwon Si Yeongtong-gu", "Gyeonggi-do", NULL, NULL);
912 char building_number[255], street[255], state[255], country_code[255], city[255], district[255], postal_code[255];
913 g_printf("Input building number: ");
914 fgets(building_number, 255, stdin);
915 building_number[strlen(building_number)-1]='\0';
916 g_printf("Input street: ");
917 fgets(street, 255, stdin);
918 street[strlen(street)-1]='\0';
919 g_printf("Input state: ");
920 fgets(state, 255, stdin);
921 state[strlen(state)-1]='\0';
922 g_printf("Input country code: ");
923 fgets(country_code, 255, stdin);
924 country_code[strlen(country_code)-1]='\0';
925 g_printf("Input city: ");
926 fgets(city, 255, stdin);
927 city[strlen(city)-1]='\0';
928 g_printf("Input district: ");
929 fgets(district, 255, stdin);
930 district[strlen(district)-1]='\0';
931 g_printf("Input postal code: ");
932 fgets(postal_code, 255, stdin);
933 postal_code[strlen(postal_code)-1]='\0';
934 data->addr = location_address_new(building_number, street, district, city, state, country_code, postal_code);
936 g_idle_add((GSourceFunc)idle_position_from_address_async, data);
937 }else if (0 == g_strcmp0("8",strOpt)) {
939 GList *pos_list = NULL;
940 GList *acc_list = NULL;
942 g_printf("[0].San jose [1].수원삼성 [2].Suwon HQ [*].Custom\n");
943 g_printf("Select Address: ");
944 int opt = PromptInt();
946 addr = g_strdup("4 N 2nd Street 95113");
948 addr = g_strdup("경기도 수원시 영통구 매탄 3동 삼성전자");
950 addr = g_strdup("Samsung Electronics Co. LTD Maetan 3-dong, Suwon Si Yeongtong-gu, Gyeonggi-Do (Seoul 443-742 Korea), Rep of KOREA");
953 g_printf("Input freeform address: ");
954 fgets(buf, 255, stdin);
955 buf[strlen(buf)-1]='\0';
956 addr = g_strdup(buf);
958 ret = location_get_position_from_freeformed_address(location_obj, addr, &pos_list, &acc_list);
960 GetLocationError(str, ret);
961 g_printf("location_get_position_from_freeformed_adress: returned value [%s]\n", str);
962 if(ret == LOCATION_ERROR_NONE){
963 g_list_foreach (pos_list, PrintPos, NULL);
964 g_list_foreach (acc_list, PrintAcc, NULL);
966 }else if(0 == g_strcmp0("8a",strOpt) ){
967 IdleData* data = g_new0(IdleData, 1);
968 data->obj = location_obj;
969 data->pos_cb = cb_position;
970 data->user_data = location_obj;
971 g_printf("[0].San jose [1].수원 삼성 [2].Suwon HQ [*].Custom\n");
972 g_printf("Select Address: ");
973 int opt = PromptInt();
975 data->str_addr = g_strdup("4 N 2nd Street 95113");
977 data->str_addr = g_strdup("경기도 수원시 영통구 매탄 3동 삼성전자");
979 data->str_addr = g_strdup("Samsung Electronics Co. LTD Maetan 3-dong, Suwon Si Yeongtong-gu, Gyeonggi-Do (Seoul 443-742 Korea), Rep of KOREA");
982 g_printf("Input freeform address: ");
983 fgets(buf, 255, stdin);
984 buf[strlen(buf)-1]='\0';
985 data->str_addr = g_strdup(buf);
987 g_idle_add((GSourceFunc)idle_position_from_freefromed_address_async, data);
989 }else if(0 == g_strcmp0("9",strOpt) ){
990 LocationVelocity *vel = NULL;
991 LocationAccuracy *acc = NULL;
992 ret = location_get_velocity(location_obj, &vel, &acc);
993 g_printf("location_get_velocity: returned value [%s]\n", str);
994 if (ret == LOCATION_ERROR_NONE) {
995 g_printf("time: [%d], speed: [%f], direction: [%f], climb: [%f]\n", vel->timestamp, vel->speed, vel->direction, vel->climb);
996 GetAccuracyLevel(str, acc->level);
997 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
1000 GetLocationError(str, ret);
1001 g_warning ("SYNC>> velocity> failed. Error[%s]", str);
1003 if(vel) location_velocity_free(vel);
1004 if(acc) location_accuracy_free(acc);
1005 }else if(0 == g_strcmp0("9a",strOpt) ){
1006 LocationVelocity *last_vel = NULL;
1007 LocationAccuracy *last_acc = NULL;
1008 ret = location_get_last_velocity (location_obj, &last_vel, &last_acc);
1009 GetLocationError(str, ret);
1010 if (ret == LOCATION_ERROR_NONE) {
1011 g_debug ("SYNC>> Last velocity> time: %d, speed: %f, direction:%f, climb:%f",
1012 last_vel->timestamp, last_vel->speed, last_vel->direction, last_vel->climb);
1013 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
1014 last_acc->level, last_acc->horizontal_accuracy, last_acc->vertical_accuracy);
1015 location_velocity_free(last_vel);
1016 location_accuracy_free(last_acc);
1017 } else g_warning ("SYNC>> Last velocity> failed. Error[%s]", str);
1018 }else if(0 == g_strcmp0("10",strOpt) ){
1019 int ret = 0, idx = 0;
1020 LocationSatellite *sat = NULL;
1027 ret = location_get_satellite (location_obj, &sat);
1028 GetLocationError(str, ret);
1029 if (ret == LOCATION_ERROR_NONE) {
1030 g_debug ("SYNC>> Current Sattelite> time = %d, satellite in view = %d, satellite in used = %d", sat->timestamp, sat->num_of_sat_inview, sat->num_of_sat_used);
1031 g_debug ("\tinview satellite information = ");
1032 for (idx=0; idx<sat->num_of_sat_inview; idx++) {
1033 location_satellite_get_satellite_details(sat, idx, &prn, &used, &elevation, &azimuth, &snr);
1034 g_debug ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d", idx, used, prn, elevation, azimuth, snr);
1036 location_satellite_free (sat);
1037 } else g_warning ("SYNC>> Current satellite> failed. Error[%s]", str);
1038 }else if(0 == g_strcmp0("10a",strOpt) ){
1039 int ret = 0, idx = 0;
1040 LocationSatellite *last_sat = NULL;
1047 ret = location_get_last_satellite (location_obj, &last_sat);
1048 GetLocationError(str, ret);
1049 if (ret == LOCATION_ERROR_NONE) {
1050 g_debug ("SYNC>> Last Sattelite> time = %d, satellite in view = %d, satellite in used = %d", last_sat->timestamp, last_sat->num_of_sat_inview, last_sat->num_of_sat_used);
1051 g_debug ("\tinview satellite information = ");
1052 for (idx=0; idx<last_sat->num_of_sat_inview; idx++) {
1053 location_satellite_get_satellite_details(last_sat, idx, &prn, &used, &elevation, &azimuth, &snr);
1054 g_debug ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d", idx, used, prn, elevation, azimuth, snr);
1056 location_satellite_free (last_sat);
1057 } else g_warning ("SYNC>> Last satellite> failed. Error[%s]", str);
1058 } else if(0 == g_strcmp0("11",strOpt) ){
1059 LocationAddress *addr = NULL;
1060 LocationAccuracy *acc = NULL;
1061 ret = location_get_address(location_obj, &addr, &acc);
1062 GetLocationError(str, ret);
1063 g_printf("location_get_address: returned value [%s]\n", str);
1064 if(ret == LOCATION_ERROR_NONE){
1065 g_printf("building number: [%s], street: [%s], state: [%s], country code: [%s], city: [%s], district: [%s], postal code: [%s]\n",
1066 addr->building_number, addr->street, addr->state, addr->country_code, addr->city, addr->district, addr->postal_code);
1067 GetAccuracyLevel(str, acc->level);
1068 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
1070 }else if(0 == g_strcmp0("11a",strOpt) ){
1071 IdleData* data = g_new0(IdleData, 1);
1072 data->obj = location_obj;
1073 data->addr_cb = cb_address;
1074 data->user_data = location_obj;
1075 g_idle_add((GSourceFunc)idle_address_async, data);
1076 }else if(0 == g_strcmp0("12",strOpt) ){
1077 LocationPosition *pos = NULL;
1078 LocationAddress *addr = NULL;
1079 LocationAccuracy *acc = NULL;
1080 g_printf("[0].San jose [1].Suwon HQ [*].Custom\n");
1081 g_printf("Select Position: ");
1082 int opt = PromptInt();
1083 if(opt == 0) pos = location_position_new(0, 37.335276, -121.890059, 0, LOCATION_STATUS_2D_FIX);
1084 else if(opt == 1) pos = location_position_new(0, 37.257809, 127.056383, 0, LOCATION_STATUS_2D_FIX);
1086 g_printf("Input latitude: ");
1087 gdouble lat = PromptDB();
1088 g_printf("Input longitude: ");
1089 gdouble lon = PromptDB();
1090 pos = location_position_new(0, lat, lon, 0, LOCATION_STATUS_2D_FIX);
1092 ret = location_get_address_from_position(location_obj, pos, &addr, &acc);
1093 GetLocationError(str, ret);
1094 g_printf("location_get_address_from_position: returned value [%s]\n", str);
1095 if(ret == LOCATION_ERROR_NONE){
1096 g_printf("building number: [%s], street: [%s], state: [%s], country code: [%s], city: [%s], district: [%s], postal code: [%s]\n",
1097 addr->building_number, addr->street, addr->state, addr->country_code, addr->city, addr->district, addr->postal_code);
1099 if(addr) location_address_free(addr);
1100 if(acc) location_accuracy_free(acc);
1101 }else if(0 == g_strcmp0("12a",strOpt) ){
1102 IdleData* data = g_new0(IdleData, 1);
1103 data->obj = location_obj;
1104 data->addr_cb = cb_address;
1105 data->user_data = location_obj;
1107 g_printf("[0].San jose [1].Suwon HQ [*].Custom\n");
1108 g_printf("Select Position: ");
1109 int opt = PromptInt();
1110 if(opt == 0) data->pos = location_position_new(0, 37.335276, -121.890059, 0, LOCATION_STATUS_2D_FIX);
1111 else if (opt == 1) data->pos = location_position_new(0, 37.257809, 127.056383, 0, LOCATION_STATUS_2D_FIX);
1113 g_printf("Input latitude: ");
1114 gdouble lat = PromptDB();
1115 g_printf("Input longitude: ");
1116 gdouble lon = PromptDB();
1117 data->pos = location_position_new(0, lat, lon, 0, LOCATION_STATUS_2D_FIX);
1119 g_idle_add((GSourceFunc)idle_address_from_position_async, data);
1120 }else if(0 == g_strcmp0("13",strOpt) ) {
1125 LocationPosition pos1, pos2;
1127 pos1.latitude = 50.0663222;
1128 pos1.longitude = -5.71475;
1130 pos2.latitude = 58.6441;
1131 pos2.longitude = -3.070094;
1133 ret = location_get_distance(&pos1, &pos2, &distance);
1134 GetLocationError(str, ret);
1135 if(ret != LOCATION_ERROR_NONE) {
1136 g_printf("Fail to get position. Error[%s]\n", str);
1139 g_printf("The approximate distance is [%lu]\n", distance);
1140 g_printf("cf.) It is approximately 969954.114 meter\n");
1142 }else if(0 == g_strcmp0("14", strOpt)) {
1144 char method_str[STR_MAX] = {0, };
1145 char input[8] = {0, };
1146 gboolean is_supported = FALSE;
1148 g_printf("0.Hybrid 1.GPS 2.WPS 3.CPS(X) 4.IPS(X) 5.SPS\n");
1149 g_printf("Select Method :");
1150 fgets(input, 8, stdin);
1151 method = atoi(input);
1153 case LOCATION_METHOD_HYBRID:
1154 is_supported = location_is_supported_method(LOCATION_METHOD_HYBRID);
1157 case LOCATION_METHOD_GPS:
1158 is_supported = location_is_supported_method(LOCATION_METHOD_GPS);
1161 case LOCATION_METHOD_WPS:
1162 is_supported = location_is_supported_method(LOCATION_METHOD_WPS);
1165 case LOCATION_METHOD_SPS:
1166 is_supported = location_is_supported_method(LOCATION_METHOD_SPS);
1169 case LOCATION_METHOD_CPS:
1170 case LOCATION_METHOD_IPS:
1175 GetMethod(method_str, method);
1177 g_printf("Method[%s] is %s.", method_str, is_supported ? "supported" : "not supported");
1179 }else if(0 == g_strcmp0("15", strOpt)) {
1180 gboolean is_enabled = FALSE;
1181 is_enabled = location_is_enabled_gps(location_obj);
1182 if(is_enabled == TRUE) g_printf("GPS is turned on");
1183 else g_printf("GPS is turned off");
1184 }else if(0 == g_strcmp0("16", strOpt)) {
1185 g_printf("location_search_poi\n");
1186 //guint req_id = 0; // move to upper
1188 LocationPOIFilter *filter = location_poi_filter_new();
1189 // gchar *key = g_strdup("KEYWORD");
1190 // gchar *value = g_strdup("pizza");
1191 // location_poi_filter_set(filter, key, value); // same with Type ? CATEGORY, KEYWORD, POIName
1192 //location_poi_filter_set(filter, "CATEGORY", "restaurant"); // error, const char* can't be free!!!!, 120214
1193 location_poi_filter_set(filter, "KEYWORD", "pizza");
1194 //location_poi_filter_set(filter, "POIName", "cafe");
1196 LocationPOIPreference *pref = location_poi_pref_new();
1197 location_poi_pref_set_max_result(pref, 2);
1198 gchar *item = g_strdup("Distance");
1199 location_poi_pref_set_sort_by(pref, item); // can't set const char* directly !!
1200 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_DESC); //LOCATION_POI_PREF_SO_ASC
1202 // only the latitude/longitude
1203 LocationPosition *position = location_position_new(0, 37.771008, -122.41175, 0, LOCATION_STATUS_2D_FIX);
1205 ret = location_search_poi(location_obj, filter, position, pref, cb_poi, NULL, &req_id);
1206 GetLocationError(str, ret);
1207 if(ret != LOCATION_ERROR_NONE) {
1208 g_printf("Fail to search POI. Error[%s]\n", str);
1210 g_printf("Seach POI success, req_id %d\n", req_id);
1215 location_poi_filter_free(filter);
1216 location_poi_pref_free(pref);
1217 location_position_free(position);
1219 }else if(0 == g_strcmp0("16a", strOpt)) {
1220 g_printf("location_search_poi_by_area\n");
1222 // only circle supported by decarta
1223 LocationPosition *center = location_position_new(0, 37.336723, -121.889555, 0, LOCATION_STATUS_2D_FIX);
1224 gdouble radius = 400;
1225 LocationBoundary *bound = location_boundary_new_for_circle(center, radius);
1227 LocationPOIFilter *filter = location_poi_filter_new();
1228 gchar *key = g_strdup("KEYWORD");
1229 gchar *value = g_strdup("cafe");
1230 location_poi_filter_set(filter, key, value); // same with Type ? CATEGORY, KEYWORD, POIName
1232 LocationPOIPreference *pref = location_poi_pref_new();
1233 location_poi_pref_set_max_result(pref, 2);
1234 gchar *item = g_strdup("Distance");
1235 location_poi_pref_set_sort_by(pref, item); // can't set const char* directly !!
1236 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); //LOCATION_POI_PREF_SO_ASC
1239 ret = location_search_poi_by_area(location_obj, filter, bound, pref, cb_poi, NULL, &req_id);
1240 GetLocationError(str, ret);
1241 if (ret != LOCATION_ERROR_NONE) {
1242 g_printf("Fail to search POI by area. Error[%s]\n", str);
1244 g_printf("Seach POI by area sucess, req_id %d\n", req_id);
1250 location_position_free(center);
1251 location_boundary_free(bound);
1252 location_poi_filter_free(filter);
1253 location_poi_pref_free(pref);
1254 }else if(0 == g_strcmp0("16b", strOpt)) {
1255 g_printf("location_search_poi_by_address\n");
1257 LocationAddress *addr = location_address_new("51", "N SAN PEDRO ST", NULL, "SAN JOSE", "SANTA CLARA", "CA", "95110");
1261 LocationPOIFilter *filter = location_poi_filter_new();
1262 gchar *key = g_strdup("KEYWORD");
1263 gchar *value = g_strdup("cafe");
1264 location_poi_filter_set(filter, key, value); // same with Type ? CATEGORY, KEYWORD, POIName
1266 LocationPOIPreference *pref = location_poi_pref_new();
1267 location_poi_pref_set_max_result(pref, 10);
1268 gchar *item = g_strdup("Distance");
1269 location_poi_pref_set_sort_by(pref, item); // can't set const char* directly !!
1270 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); //LOCATION_POI_PREF_SO_ASC
1272 ret = location_search_poi_by_address(location_obj, filter, addr, pref, cb_poi, NULL, &req_id);
1273 GetLocationError(str, ret);
1274 if(ret != LOCATION_ERROR_NONE) {
1275 g_printf("Fail to search POI by address. Error[%s]\n", str);
1277 g_printf("Seach POI by address sucess, req_id %d\n", req_id);
1284 location_address_free(addr);
1285 location_poi_filter_free(filter);
1286 location_poi_pref_free(pref);
1287 }else if(0 == g_strcmp0("16c", strOpt)) {
1288 g_printf("location_search_poi_by_freeformed_address\n");
1290 gchar *addr = g_strdup("North Second St.");
1292 LocationPOIFilter *filter = location_poi_filter_new();
1293 gchar *key = g_strdup("KEYWORD");
1294 gchar *value = g_strdup("restaurant");
1295 location_poi_filter_set(filter, key, value); // same with Type ? CATEGORY, KEYWORD, POIName
1297 LocationPOIPreference *pref = location_poi_pref_new();
1298 location_poi_pref_set_max_result(pref, 10);
1299 gchar *item = g_strdup("Distance");
1300 location_poi_pref_set_sort_by(pref, item); // can't set const char* directly !!
1301 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); //LOCATION_POI_PREF_SO_ASC
1303 ret = location_search_poi_by_freeformed_address(location_obj, filter, addr, pref, cb_poi, NULL, &req_id);
1304 GetLocationError(str, ret);
1305 if (ret != LOCATION_ERROR_NONE) {
1306 g_printf("Fail to search POI by address. Error[%s]\n", str);
1308 g_printf("Seach POI by address success, req_id %d\n", req_id);
1316 location_poi_filter_free(filter);
1317 location_poi_pref_free(pref);
1318 }else if(0 == g_strcmp0("16d", strOpt)) {
1319 gchar value[255] = {0, };
1321 // only circle supported by decarta
1322 LocationPosition *center = location_position_new(0, 37.56693, 126.97819, 0, LOCATION_STATUS_2D_FIX);
1323 gdouble radius = 800;
1324 LocationBoundary *bound = location_boundary_new_for_circle(center, radius);
1326 LocationPOIFilter *filter = location_poi_filter_new();
1328 g_printf("Input keyword :");
1330 gchar *key = g_strdup("KEYWORD");
1331 location_poi_filter_set(filter, key, value); // same with Type ? CATEGORY, KEYWORD, POIName
1333 LocationPOIPreference *pref = location_poi_pref_new();
1334 location_poi_pref_set_max_result(pref, 2);
1335 gchar *item = g_strdup("Distance");
1336 location_poi_pref_set_sort_by(pref, item); // can't set const char* directly !!
1337 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC); //LOCATION_POI_PREF_SO_ASC
1340 ret = location_search_poi_by_area(location_obj, filter, bound, pref, cb_poi, NULL, &req_id);
1341 GetLocationError(str, ret);
1342 if (ret != LOCATION_ERROR_NONE) {
1343 g_printf("Fail to search POI by area. Error[%s]\n", str);
1345 g_printf("Seach POI by area sucess, req_id %d\n", req_id);
1351 location_position_free(center);
1352 location_boundary_free(bound);
1353 location_poi_filter_free(filter);
1354 location_poi_pref_free(pref);
1355 }else if(0 == g_strcmp0("16e", strOpt)) {
1358 g_printf("Input ReqID : ");
1359 scanf("%d", &req_id);
1361 ret = location_cancel_poi_request(location_obj, req_id);
1362 GetLocationError(str, ret);
1363 if (ret != LOCATION_ERROR_NONE) {
1364 g_printf("Fail to cancel POI request. Error[%s]\n", str);
1367 g_printf("location_cancel_poi_request, req_id %d\n", req_id);
1368 }else if(0 == g_strcmp0("17", strOpt)) {
1369 g_printf("17. location_request_route\n\n");
1371 LocationPosition *origin = location_position_new(0, 37.564263, 126.974676, 0, LOCATION_STATUS_2D_FIX); // Seoul city hall
1372 LocationPosition *destination = location_position_new(0, 37.557120, 126.992410, 0, LOCATION_STATUS_2D_FIX); // NamSan
1374 GList *waypoint = NULL;
1375 LocationPosition *via_pos = location_position_new(0, 37.560950, 126.986240, 0, LOCATION_STATUS_2D_FIX); // Wangsimli
1376 waypoint = g_list_append (waypoint, (gpointer)via_pos);
1378 LocationRoutePreference *pref = location_route_pref_new();
1379 location_route_pref_set_route_type(pref, "FASTEST");
1381 ret = location_request_route(location_obj, origin, destination, waypoint, pref, cb_route, NULL, &req_id);
1382 GetLocationError(str, ret);
1383 if (ret != LOCATION_ERROR_NONE) {
1384 g_printf("Fail to search route by address. Error[%s]\n", str);
1386 g_printf("Search Route successfully, req_id %d\n", req_id);
1388 }else if(0 == g_strcmp0("17a", strOpt)) {
1389 g_printf("17a. location_cancel_route_request\n");
1392 g_printf("Input ReqID : ");
1393 scanf("%d", &req_id);
1395 ret = location_cancel_route_request(location_obj, req_id);
1396 GetLocationError(str, ret);
1397 if (ret != LOCATION_ERROR_NONE) {
1398 g_printf("Fail to cancel route request. Error[%s]\n", str);
1401 g_printf("location_cancel_route_request, req_id %d\n", req_id);
1404 }else if (0 == g_strcmp0 ("18", strOpt)) {
1406 for (idx = 0; idx < MAP_SERVICE_TYPE_MAX; idx++) {
1407 g_printf("[%d:%d], ", idx, location_is_supported_map_provider_capability (location_obj, idx));
1409 }else if (0 == g_strcmp0 ("19", strOpt)) {
1411 for (idx = 0; idx < MAP_SERVICE_TYPE_MAX; idx++) {
1412 g_printf("[%d:", idx);
1413 print_map_service_keys(location_obj, idx);
1416 }else if(0 == g_strcmp0("99", strOpt)) {
1418 const *str = "command";
1419 ret = location_send_command(str);
1421 g_printf("Success to send command[%s]", str);
1422 }else if(0 == g_strcmp0("a1",strOpt)){
1423 if(location_obj && !g_sig_enable) {
1424 g_sig_enable = g_signal_connect (location_obj, "service-enabled", G_CALLBACK(cb_service_enabled), location_obj);
1426 }else if(0 == g_strcmp0("a2",strOpt)){
1427 if(location_obj && !g_sig_disable){
1428 g_sig_disable = g_signal_connect (location_obj, "service-disabled", G_CALLBACK(cb_service_disabled), location_obj);
1430 }else if(0 == g_strcmp0("a3",strOpt)){
1431 if(location_obj && !g_sig_update){
1432 g_sig_update = g_signal_connect (location_obj, "service-updated", G_CALLBACK(cb_service_updated), location_obj);
1434 }else if(0 == g_strcmp0("a4",strOpt)){
1435 if(location_obj && !g_sig_zonein){
1436 g_sig_zonein = g_signal_connect (location_obj, "zone-in", G_CALLBACK(cb_zone_in), location_obj);
1438 }else if(0 == g_strcmp0("a5",strOpt)){
1439 if(location_obj && !g_sig_zoneout){
1440 g_sig_zoneout = g_signal_connect (location_obj, "zone-out", G_CALLBACK(cb_zone_out), location_obj);
1442 }else if(0 == g_strcmp0("b1",strOpt)){
1443 if(location_obj && g_sig_enable) {
1444 g_signal_handler_disconnect (location_obj, g_sig_enable);
1447 }else if(0 == g_strcmp0("b2",strOpt)){
1448 if(location_obj && g_sig_disable){
1449 g_signal_handler_disconnect (location_obj, g_sig_disable);
1452 }else if(0 == g_strcmp0("b3",strOpt)){
1453 if(location_obj && g_sig_update){
1454 g_signal_handler_disconnect (location_obj, g_sig_update);
1457 }else if(0 == g_strcmp0("b4",strOpt)){
1458 if(location_obj && g_sig_zonein){
1459 g_signal_handler_disconnect (location_obj, g_sig_zonein);
1462 }else if(0 == g_strcmp0("b5",strOpt)){
1463 if(location_obj && g_sig_zoneout){
1464 g_signal_handler_disconnect (location_obj, g_sig_zoneout);
1467 }else if(0 == g_strcmp0("c1",strOpt)){
1468 LocationBoundary* bound = NULL;
1470 int polygon_count = json_util_get_polygon_count();
1472 g_printf("[0].San jose(Rect) [1].Suwon HQ(Rect) [2].Seoul City(circle) ");
1473 for(i = 0; i < polygon_count; i++)
1474 g_printf("[%d].%s ", i + 3, json_util_get_polygon_name(i));
1476 g_printf("\nSelect Boundary: ");
1477 int opt = PromptInt();
1479 LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX);
1480 LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX);
1481 bound = location_boundary_new_for_rect (lt, rb);
1482 location_position_free(rb);
1483 location_position_free(lt);
1485 location_boundary_add(location_obj, bound);
1487 } else if(opt == 1) {
1488 LocationPosition* rb = location_position_new (0, 37.255, 127.058, 0, LOCATION_STATUS_2D_FIX);
1489 LocationPosition* lt = location_position_new (0, 37.260, 127.045, 0, LOCATION_STATUS_2D_FIX);
1490 bound = location_boundary_new_for_rect (lt, rb);
1491 location_position_free(rb);
1492 location_position_free(lt);
1494 location_boundary_add(location_obj, bound);
1495 } else if(opt == 2) {
1496 LocationPosition *center = location_position_new(0, 37.566535, 126.977969, 0.0, LOCATION_STATUS_2D_FIX);
1497 double radius = 10.0;
1498 bound = location_boundary_new_for_circle(center, radius);
1500 location_boundary_add(location_obj, bound);
1501 } else if (opt > 2 && opt < 3 + polygon_count) {
1503 int polygon_index = opt - 3;
1504 bound = json_util_get_polygon_boundary(polygon_index);
1505 location_boundary_add(location_obj, bound);
1507 LocationPosition * check_pos = NULL;
1508 gboolean ret = FALSE;
1509 int count = json_util_get_marker_position_count(polygon_index);
1510 for(index = 0; index < count; index++) {
1511 check_pos = json_util_get_marker_position(polygon_index, index);
1513 ret = location_boundary_if_inside(bound, check_pos);
1514 g_printf("[%s] is [%s] and the test result is [%s]\n", json_util_get_marker_name(polygon_index, index), json_util_result_zone_test(polygon_index, index), ret == TRUE? "inside": "outside");
1515 location_position_free(check_pos);
1518 g_printf("boundary is not set\n");
1520 location_boundary_free(bound);
1522 }else if(0 == g_strcmp0("c2",strOpt)){
1523 g_printf("Get Boundary\n");
1524 location_boundary_foreach(location_obj, PrintBoundary, NULL);
1526 }else if(0 == g_strcmp0("c3",strOpt)){
1527 g_printf("Remove Boundary\n");
1528 LocationBoundary* bound = NULL;
1531 int polygon_count = json_util_get_polygon_count();
1533 g_printf("[0].San jose(Rect) [1].Suwon HQ(Rect) [2].Seoul City(circle) ");
1534 for(i = 0; i < polygon_count; i++)
1535 g_printf("[%d].%s ", i + 3, json_util_get_polygon_name(i));
1537 g_printf("\nSelect Boundary: ");
1538 int opt = PromptInt();
1540 LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX);
1541 LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX);
1542 bound = location_boundary_new_for_rect (lt, rb);
1543 location_position_free(rb);
1544 location_position_free(lt);
1546 } else if(opt == 1) {
1547 LocationPosition* rb = location_position_new (0, 37.255, 127.058, 0, LOCATION_STATUS_2D_FIX);
1548 LocationPosition* lt = location_position_new (0, 37.260, 127.045, 0, LOCATION_STATUS_2D_FIX);
1549 bound = location_boundary_new_for_rect (lt, rb);
1550 location_position_free(rb);
1551 location_position_free(lt);
1553 } else if(opt == 2) {
1554 LocationPosition *center = location_position_new(0, 37.566535, 126.977969, 0.0, LOCATION_STATUS_2D_FIX);
1555 double radius = 10.0;
1556 bound = location_boundary_new_for_circle(center, radius);
1557 location_position_free(center);
1559 } else if (opt > 2 && opt < 3 + polygon_count) {
1560 int polygon_index = opt - 3;
1561 bound = json_util_get_polygon_boundary(polygon_index);
1563 g_printf("Invalid value\n");
1566 if(bound != NULL) location_boundary_remove(location_obj, bound);
1568 }else if(0 == g_strcmp0("c4",strOpt)){
1569 location_boundary_foreach(location_obj, RemoveBoundary, location_obj);
1570 }else if(0 == g_strcmp0("c5",strOpt)){
1572 g_printf("Input device name: ");
1573 fgets(buf, 255, stdin);
1574 buf[strlen(buf)-1]='\0';
1575 g_object_set(location_obj, "dev-name", buf, NULL);
1576 } else if (0 == g_strcmp0("c6", strOpt)) {
1578 g_printf("Input interval[1~120]:");
1579 scanf("%u", &interval);
1580 g_printf("changed interval to [%u]\n", interval);
1581 g_object_set(location_obj, "update-interval", interval, NULL);
1582 }else if(0 == g_strcmp0("q",strOpt) ){
1583 g_main_loop_quit(g_mainloop);
1587 g_thread_join(g_main);
1588 g_printf("\n--- Exit LBS Test App ---\n");