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.
23 #ifndef __LOCATION_MAP_SERVICE_H__
24 #define __LOCATION_MAP_SERVICE_H__
28 #include <location-map-pref.h>
29 #include <location-map-types.h>
30 #include <location-address.h>
31 #include <location-poi.h>
32 #include <location-route.h>
33 #include <location-landmark.h>
38 * @file location-map-service.h
39 * @brief This file contains the Location API and related structure and enumeration.
42 * @addtogroup LocationFW
44 * @defgroup LocationMapService Location Map Service API
45 * @brief This sub module provides the Location Map Service API.
46 * @addtogroup LocationMapService
53 * @remarks location_init should be called before.
57 * provider - map provider. A default provider will be provided if NULL.
59 LocationMapObject *location_map_new (const char *provider);
64 * @remarks location_map_new should be called before.
66 int location_map_free (LocationMapObject *obj);
70 * Get current position information with estimate of the accuracy by using given address information.
71 * @remarks Out parameters are should be freed.
73 * #location_init should be called before.\n
74 * Calling application must have an active data connection.
77 * obj - a #LocationMapObject created by #location_map_new
79 * address - a #LocationAddress
81 * position_list - a list of #LocationPosition
83 * accuracy_list - a list of #LocationAccuracy
87 * Please refer #LocationError for more information.
89 * location_map_get_position_from_address_async\n
93 #include <location-map-service.h>
95 static void PrintPos (gpointer data, gpointer user_data)
97 LocationPosition *pos = (LocationPosition *)data;
100 g_debug("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
101 location_position_free (pos);
105 static void PrintAcc (gpointer data, gpointer user_data)
107 LocationAccuracy *acc = (LocationAccuracy *)data;
110 g_debug("level: [%d], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
111 location_accuracy_free (acc);
116 static void PrintPos (gpointer data, gpointer user_data)
118 LocationPosition *pos = (LocationPosition *)data;
121 g_debug("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
122 location_position_free (pos);
126 static void PrintAcc (gpointer data, gpointer user_data)
128 LocationAccuracy *acc = (LocationAccuracy *)data;
131 g_debug("level: [%d], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
132 location_accuracy_free (acc);
136 int main (int argc, char *argv[])
138 LocationMapObject *loc = NULL;
139 int ret = LOCATION_ERROR_NONE;
142 loc = location_map_new (NULL);
144 g_debug("location_map_new failed");
148 GList *pos_list = NULL;
149 GList *acc_list = NULL;
150 LocationAddress *addr = NULL;
152 addr = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113");
153 if (LOCATION_ERROR_NONE == location_map_get_position_from_address(loc, addr, &pos_list, &acc_list)) {
155 } else g_warning ("SYNC>> position from address> failed");
156 location_address_free (addr);
157 g_list_foreach (pos_list, PrintPos, NULL);
158 g_list_foreach (acc_list, PrintAcc, NULL);
159 g_list_free (pos_list);
160 g_list_free (acc_list);
161 location_map_free (loc);
166 int location_map_get_position_from_address (LocationMapObject *obj, const LocationAddress *address, GList **position_list, GList **accuracy_list);
170 * Get current position information asynchronously with estimate of the accuracy by using given address information.
173 * #location_init should be called before.\n
174 * Calling application must have glib or ecore main loop.\n
175 * Calling application must have an active data connection.
178 * obj - a #LocationMapObject created by #location_map_new
180 * address - a #LocationAddress
182 * callback - A pointer of function which will be called after position is gained or when an error occurs.
184 * userdata - data to pass to function
188 * Please refer #LocationError for more information.
190 * location_map_get_position_from_address\n
193 #include <location-map-service.h>
195 static void PrintPos (gpointer data, gpointer user_data)
197 LocationPosition *pos = (LocationPosition *)data;
200 g_debug("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
204 static void PrintAcc (gpointer data, gpointer user_data)
206 LocationAccuracy *acc = (LocationAccuracy *)data;
209 g_debug("level: [%d], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
213 cb_position_from_address (LocationError error, GList *position_list, GList *accuracy_list, gpointer userdata)
215 if (position_list && accuracy_list) {
216 g_list_foreach (position_list, PrintPos);
217 g_list_foreach (accuracy_list, PrintAcc);
221 void get_position_from_address(LocationMapObject* loc)
223 LocationAddress *addr = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113");
224 //Calling application must have an active data connection before using this function.
225 if (LOCATION_ERROR_NONE == location_map_get_position_from_address_async(loc, addr, cb_position_from_address, loc))
226 g_debug("location_map_get_position_from_address_async() success");
227 else g_warning ("location_map_get_position_from_address_async() failed");
228 location_address_free (addr);
232 int location_map_get_position_from_address_async (LocationMapObject *obj, const LocationAddress *address, LocationPositionCB callback, gpointer userdata);
236 * Get current position information with estimate of the accuracy by using given free-formed address string.
237 * @remarks Out parameters are should be freed.
239 * #location_init should be called before.\n
240 * Calling application must have an active data connection.
243 * obj - a #LocationMapObject created by #location_map_new
245 * address - Free-formed address string to be used
247 * position_list - a list of #LocationPosition
249 * accuracy_list - a list of #LocationAccuracy
253 * Please refer #LocationError for more information.
255 * location_map_get_position_from_freeformed_address_async\n
258 #include <location.h>
259 #include <location-map-service.h>
261 static void PrintPos (gpointer data, gpointer user_data)
263 LocationPosition *pos = (LocationPosition *)data;
266 g_debug("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
267 location_position_free (pos);
271 static void PrintAcc (gpointer data, gpointer user_data)
273 LocationAccuracy *acc = (LocationAccuracy *)data;
276 g_debug("level: [%d], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
277 location_accuracy_free (acc);
281 static void PrintPos (gpointer data, gpointer user_data)
283 LocationPosition *pos = (LocationPosition *)data;
286 g_debug("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
287 location_position_free (pos);
291 static void PrintAcc (gpointer data, gpointer user_data)
293 LocationAccuracy *acc = (LocationAccuracy *)data;
296 g_debug("level: [%d], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
297 location_accuracy_free (acc);
301 int main (int argc, char *argv[])
303 LocationMapObject *loc = NULL;
304 int ret = LOCATION_ERROR_NONE;
307 loc = location_map_new (NULL);
309 g_debug("location_map_new failed");
313 GList *pos_list = NULL;
314 GList *acc_list = NULL;
315 char* addr_str = g_strdup("4 N 2nd Street 95113");
317 //Calling application must have an active data connection before using this function.
318 if (LOCATION_ERROR_NONE == location_map_get_position_from_freeformed_address(loc, addr_str, &pos_list, &acc_list)) {
319 g_list_foreach (pos_list, PrintPos, NULL);
320 g_list_foreach (acc_list, PrintAcc, NULL);
321 g_list_free (pos_list);
322 g_list_free (acc_list);
323 } else g_warning ("SYNC>> position from freeformed address> failed");
331 int location_map_get_position_from_freeformed_address (LocationMapObject *obj, const gchar *address, GList **position_list, GList **accuracy_list);
335 * Get current position information asynchronously with estimate of the accuracy by using given free-formed address string.
338 * #location_init should be called before.\n
339 * Calling application must have glib or ecore main loop.\n
340 * Calling application must have an active data connection.
343 * obj - a #LocationMapObject created by #location_map_new
345 * address - Free-formed address string to be used
347 * callback - A pointer of function which will be called after position is gained or when an error occurs.
349 * userdata - data to pass to function
353 * Please refer #LocationError for more information.
355 * location_map_get_position_from_freeformed_address\n
358 #include <location.h>
359 #include <location-map-service.h>
361 static void PrintPos (gpointer data, gpointer user_data)
363 LocationPosition *pos = (LocationPosition *)data;
366 g_debug("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
370 static void PrintAcc (gpointer data, gpointer user_data)
372 LocationAccuracy *acc = (LocationAccuracy *)data;
375 g_debug("level: [%d], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
380 cb_position_from_freeformed_address (LocationError error, GList *position_list, GList *accuracy_list, gpointer userdata)
382 if (position_list && accuracy_list) {
383 g_list_foreach (position_list, PrintPos);
384 g_list_foreach (accuracy_list, PrintAcc);
388 void get_position_from_address(LocationMapObject* loc)
390 gchar *addr_str = g_strdup("4 N 2nd Street 95113");
391 //Calling application must have an active data connection before using this function.
392 if (LOCATION_ERROR_NONE == location_map_get_position_from_freeformed_address_async(loc, addr_str, cb_position_from_freeformed_address, loc))
393 g_debug("location_map_get_position_from_freeformed_address_async() success");
394 else g_warning ("location_map_get_position_from_freeformed_address_async() failed");
400 int location_map_get_position_from_freeformed_address_async (LocationMapObject *obj, const gchar *address, LocationPositionCB callback, gpointer userdata);
404 * Get current address information with estimate of the accuracy by using given position information.
405 * @remarks Out parameters are should be freed.
407 * #location_init should be called before.\n
408 * Calling application must have an active data connection.
411 * obj - a #LocationMapObject created by #location_map_new
413 * position - a #LocationPosition
415 * address - a new #LocationAddress
417 * accuracy - a new #LocationAccuracy
421 * Please refer #LocationError for more information.
423 * location_map_get_address_from_position_async\n
426 #include <location.h>
427 #include <location-map-service.h>
428 static GMainLoop *loop = NULL;
431 main (int argc, char *argv[])
433 LocationMapObject *loc = NULL;
434 int ret = LOCATION_ERROR_NONE;
438 loop = g_main_loop_new (NULL, TRUE);
440 loc = location_map_new (NULL);
442 g_debug("location_map_new failed");
446 LocationPosition *pos = NULL;
447 LocationAccuracy *acc = NULL;
448 LocationAddress *addr = NULL;
450 //Calling application must have an active data connection before using this function.
451 pos = location_position_new (0, 37.257809, 127.056383, 0, LOCATION_STATUS_2D_FIX);
452 if (LOCATION_ERROR_NONE == location_map_get_address_from_position(loc, pos, &addr, &acc)) {
453 g_debug ("SYNC>> address from position> %s %s %s %s %s %s %s",
454 addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code);
455 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
456 location_address_free(addr);
457 location_accuracy_free(acc);
458 } else g_warning ("SYNC>> address from position> failed");
459 location_position_free (pos);
460 location_map_free (loc);
464 int location_map_get_address_from_position (LocationMapObject *obj, const LocationPosition *position, LocationAddress **address, LocationAccuracy **accuracy);
468 * Get current address information asynchronously with estimate of the accuracy by using given position information.
471 * #location_init should be called before.\n
472 * Calling application must have glib or ecore main loop.\n
473 * Calling application must have an active data connection.
476 * obj - a #LocationMapObject created by #location_map_new
478 * position - a #LocationPosition
480 * callback - A pointer of function which will be called after address is gained or when an error occurs.
482 * userdata - data to pass to function
486 * Please refer #LocationError for more information.
488 * location_map_get_address_from_position\n
491 #include <location.h>
492 #include <location-map-service.h>
493 static GMainLoop *loop = NULL;
496 cb_address_from_position (LocationError error, LocationAddress *addr, LocationAccuracy *acc, gpointer userdata)
498 g_debug ("ASYNC>> location_map_get_address_from_position_async> %s %s %s %s %s %s %s",
499 addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code);
500 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
503 void get_address_from_position(LocationMapObject* loc)
505 LocationPosition *pos = location_position_new (0, 37.257809, 127.056383, 0, LOCATION_STATUS_2D_FIX);
506 //Calling application must have an active data connection before using this function.
507 if (LOCATION_ERROR_NONE == location_map_get_address_from_position_async(loc, pos, cb_address_from_position, loc))
508 g_debug("location_map_get_address_from_position_async() success");
509 else g_warning ("location_map_get_address_from_position_async() failed");
510 location_position_free (pos);
514 int location_map_get_address_from_position_async (LocationMapObject *obj, const LocationPosition *position, LocationAddressCB callback, gpointer userdata);
517 * @brief Request a search service from service provider.
518 * @remarks refer #LocationLandmark
519 * @pre #location_init should be called before.\n
520 * #location_poi_pref_new should be set before.
522 * @param [in] obj - a #LocationMapObject created by #location_map_new
523 * @param [in] filter - a #LocaitonPOIFilter created by #location_poi_filter_new
524 * @param [in] position - a #LocationPosition
525 * @param [in] pref - a #LocationPOIPreference created by #location_poi_pref_new
526 * @param [in] cb - #LocationPOICB
527 * @param [in] user_data - data to pass to function
528 * @param [out] req_id - a guint
531 * Please refer #LocationError for more information.
534 #include <location.h>
535 #include <location-map-service.h>
537 static GMainLoop *loop = NULL;
539 void PrintLandmarkCb (gpointer data, gpointer user_data)
541 g_return_if_fail (data);
543 LocationLandmark *landmark = (LocationLandmark *)data;
545 g_debug ("id[%d], Priority[%d], Name:[%s], Author[%s], Phone[%s], Category[%s]\n", location_landmark_get_id (landmark),
546 location_landmark_get_priority(landmark),
547 location_landmark_get_name(landmark),
548 location_landmark_get_author(landmark),
549 location_landmark_get_phone_number(landmark),
550 location_landmark_get_category(landmark));
553 static void poi_cb(LocationError error, guint req_id, GList * landmark_list, gchar * error_code, gchar * error_msg, gpointer userdata)
555 if (error != LOCATION_ERROR_NONE || landmark_list == NULL) {
556 g_debug ("Fail to get poi. Error[%d], ErrCode[%s], ErrMsg[%s]", error, error_code, error_msg);
559 g_list_foreach (landmark_list, PrintLandmarkCb, NULL);
562 void search_poi(LocationMapObject* loc)
566 LocationPosition *pos = location_position_new (0, 37.257809, 127.056383, 0, LOCATION_STATUS_2D_FIX);
567 LocationPOIFilter *filter = location_poi_filter_new();
568 LocationPOIPreference *pref = location_poi_pref_new();
570 location_poi_filter_set(filter, "CATEGORY", "restaurant");
572 location_poi_pref_set_max_result(pref, 5);
573 location_poi_pref_set_sort_by(pref, "name");
574 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC);
576 ret = location_map_search_poi (loc, filter, pos, pref, poi_cb, loc, &req_id);
577 if (ret != LOCATION_ERROR_NONE) {
578 g_debug("Fail to get poi. Error[%d]", ret);
581 location_poi_filter_free(filter);
582 location_poi_pref_free(pref);
583 location_position_free(pos);
588 int location_map_search_poi (LocationMapObject *obj, const LocationPOIFilter * filter, const LocationPosition *position, const LocationPOIPreference * pref, LocationPOICB cb, gpointer user_data, guint * req_id);
591 * @brief Request a search service with area filter from service provider.
592 * @remarks refer #LocationLandmark
593 * @pre #location_init should be called before.\n
594 * #location_poi_pref_new should be set before.
596 * @param [in] obj - a #LocationMapObject created by #location_map_new
597 * @param [in] filter - a #LocaitonPOIFilter created by #location_poi_filter_new
598 * @param [in] boundary - a #LocationBoundary
599 * @param [in] pref - a #LocationPOIPreference created by #location_poi_pref_new
600 * @param [in] cb - #LocationPOICB
601 * @param [in] user_data - data to pass to function
602 * @param [out] req_id - a guint
605 * Please refer #LocationError for more information.
608 #include <location.h>
609 #include <location-map-service.h>
611 static GMainLoop *loop = NULL;
613 void PrintLandmarkCb (gpointer data, gpointer user_data)
615 g_return_if_fail (data);
617 LocationLandmark *landmark = (LocationLandmark *)data;
619 g_debug ("id[%d], Priority[%d], Name:[%s], Author[%s], Phone[%s], Category[%s]\n", location_landmark_get_id (landmark),
620 location_landmark_get_priority(landmark),
621 location_landmark_get_name(landmark),
622 location_landmark_get_author(landmark),
623 location_landmark_get_phone_number(landmark),
624 location_landmark_get_category(landmark));
627 static void poi_cb(LocationError error, guint req_id, GList * landmark_list, gchar * error_code, gchar * error_msg, gpointer userdata)
629 if (error != LOCATION_ERROR_NONE || landmark_list == NULL) {
630 g_debug ("Fail to get poi. Error[%d], ErrCode[%s], ErrMsg[%s]", error, error_code, error_msg);
633 g_list_foreach (landmark_list, PrintLandmarkCb, NULL);
636 void search_poi(LocationMapObject* loc)
641 LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX);
642 LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX);
643 LocationBoundary *bbox = location_boundary_new_for_rect (lt, rb);
644 LocationPOIFilter *filter = location_poi_filter_new();
645 LocationPOIPreference *pref = location_poi_pref_new();
647 location_poi_filter_set(filter, "CATEGORY", "restaurant");
649 location_poi_pref_set_max_result(pref, 5);
650 location_poi_pref_set_sort_by(pref, "name");
651 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC);
653 ret = location_map_search_poi_by_area (loc, filter, bbox, pref, poi_cb, loc, &req_id);
654 if (ret != LOCATION_ERROR_NONE) {
655 g_debug("Fail to get poi. Error[%d]", ret);
658 location_poi_filter_free(filter);
659 location_poi_pref_free(pref);
660 location_boundary_free (bbox);
664 int location_map_search_poi_by_area (LocationMapObject *obj, const LocationPOIFilter * filter, const LocationBoundary * boundary, const LocationPOIPreference * pref, LocationPOICB cb, gpointer user_data, guint * req_id);
667 * @brief Request a search service with address filter from service provider.
668 * @remarks refer #LocationLandmark
669 * @pre #location_init should be called before.\n
670 * #location_poi_pref_new should be set before.
672 * @param [in] obj - a #LocationMapObject created by #location_map_new
673 * @param [in] filter - a #LocaitonPOIFilter created by #location_poi_filter_new
674 * @param [in] address - a #LocationAddress
675 * @param [in] pref - a #LocationPOIPreference created by #location_poi_pref_new
676 * @param [in] cb - #LocationPOICB
677 * @param [in] user_data - data to pass to function
678 * @param [out] req_id - a guint
681 * Please refer #LocationError for more information.
684 #include <location.h>
685 #include <location-map-service.h>
687 static GMainLoop *loop = NULL;
689 void PrintLandmarkCb (gpointer data, gpointer user_data)
691 g_return_if_fail (data);
693 LocationLandmark *landmark = (LocationLandmark *)data;
695 g_debug ("id[%d], Priority[%d], Name:[%s], Author[%s], Phone[%s], Category[%s]\n", location_landmark_get_id (landmark),
696 location_landmark_get_priority(landmark),
697 location_landmark_get_name(landmark),
698 location_landmark_get_author(landmark),
699 location_landmark_get_phone_number(landmark),
700 location_landmark_get_category(landmark));
703 static void poi_cb(LocationError error, guint req_id, GList * landmark_list, gchar * error_code, gchar * error_msg, gpointer userdata)
705 if (error != LOCATION_ERROR_NONE || landmark_list == NULL) {
706 g_debug ("Fail to get poi. Error[%d], ErrCode[%s], ErrMsg[%s]", error, error_code, error_msg);
709 g_list_foreach (landmark_list, PrintLandmarkCb, NULL);
712 void search_poi(LocationMapObject* loc)
717 LocationAddress *addr = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113");
718 LocationPOIFilter *filter = location_poi_filter_new();
719 LocationPOIPreference *pref = location_poi_pref_new();
721 location_poi_filter_set(filter, "CATEGORY", "restaurant");
723 location_poi_pref_set_max_result(pref, 5);
724 location_poi_pref_set_sort_by(pref, "name");
725 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC);
727 ret = location_map_search_poi_by_address (loc, filter, addr, pref, poi_cb, loc, &req_id);
728 if (ret != LOCATION_ERROR_NONE) {
729 g_debug("Fail to get poi. Error[%d]", ret);
732 location_poi_filter_free(filter);
733 location_poi_pref_free(pref);
734 location_address_free (addr);
738 int location_map_search_poi_by_address (LocationMapObject *obj, const LocationPOIFilter * filter, const LocationAddress * addr, const LocationPOIPreference * pref, LocationPOICB cb, gpointer user_data, guint * req_id);
741 * @brief Request a search service with area filter from service provider.
742 * @remarks refer #LocationLandmark
743 * @pre #location_init should be called before.\n
744 * #location_poi_pref_new should be set before.
746 * @param [in] obj - a #LocationMapObject created by #location_map_new
747 * @param [in] filter - a #LocaitonPOIFilter created by #location_poi_filter_new
748 * @param [in] address - a freeformed address
749 * @param [in] pref - a #LocationPOIPreference created by #location_poi_pref_new
750 * @param [in] cb - #LocationPOICB
751 * @param [in] user_data - data to pass to function
752 * @param [out] req_id - a guint
755 * Please refer #LocationError for more information.
758 #include <location.h>
759 #include <location-map-service.h>
761 static GMainLoop *loop = NULL;
763 void PrintLandmarkCb (gpointer data, gpointer user_data)
765 g_return_if_fail (data);
767 LocationLandmark *landmark = (LocationLandmark *)data;
769 g_debug ("id[%d], Priority[%d], Name:[%s], Author[%s], Phone[%s], Category[%s]\n", location_landmark_get_id (landmark),
770 location_landmark_get_priority(landmark),
771 location_landmark_get_name(landmark),
772 location_landmark_get_author(landmark),
773 location_landmark_get_phone_number(landmark),
774 location_landmark_get_category(landmark));
777 static void poi_cb(LocationError error, guint req_id, GList * landmark_list, gchar * error_code, gchar * error_msg, gpointer userdata)
779 if (error != LOCATION_ERROR_NONE || landmark_list == NULL) {
780 g_debug ("Fail to get poi. Error[%d], ErrCode[%s], ErrMsg[%s]", error, error_code, error_msg);
783 g_list_foreach (landmark_list, PrintLandmarkCb, NULL);
786 void search_poi(LocationMapObject* loc)
791 gchar *addr = g_strdup("4 N 2nd Street 95113");
792 LocationPOIFilter *filter = location_poi_filter_new();
793 LocationPOIPreference *pref = location_poi_pref_new();
795 location_poi_filter_set(filter, "CATEGORY", "restaurant");
797 location_poi_pref_set_max_result(pref, 5);
798 location_poi_pref_set_sort_by(pref, "name");
799 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC);
801 ret = location_map_search_poi_by_freeformed_address (loc, filter, addr, pref, poi_cb, loc, &req_id);
802 if (ret != LOCATION_ERROR_NONE) {
803 g_debug("Fail to get poi. Error[%d]", ret);
806 location_poi_filter_free(filter);
807 location_poi_pref_free(pref);
812 int location_map_search_poi_by_freeformed_address (LocationMapObject *obj, const LocationPOIFilter * filter, const gchar * address, const LocationPOIPreference * pref, LocationPOICB cb, gpointer user_data, guint * req_id);
815 * @brief Cancel the previous poi search.
816 * @remarks refer #LocationLandmark
817 * @pre #location_map_search_poi should be called before.
819 * @param [in] obj - a #LocationMapObject created by #location_map_new
820 * @param [in] req_id - a poi request id returned by location_map_search_poi
823 * Please refer #LocationError for more information.
826 #include <location.h>
827 #include <location-map-service.h>
829 static GMainLoop *loop = NULL;
831 void PrintLandmarkCb (gpointer data, gpointer user_data)
833 g_return_if_fail (data);
835 LocationLandmark *landmark = (LocationLandmark *)data;
837 g_debug ("id[%d], Priority[%d], Name:[%s], Author[%s], Phone[%s], Category[%s]\n", location_landmark_get_id (landmark),
838 location_landmark_get_priority(landmark),
839 location_landmark_get_name(landmark),
840 location_landmark_get_author(landmark),
841 location_landmark_get_phone_number(landmark),
842 location_landmark_get_category(landmark));
845 static void poi_cb(LocationError error, guint req_id, GList * landmark_list, gchar * error_code, gchar * error_msg, gpointer userdata)
847 if (error != LOCATION_ERROR_NONE || landmark_list == NULL) {
848 g_debug ("Fail to get poi. Error[%d], ErrCode[%s], ErrMsg[%s]", error, error_code, error_msg);
851 g_list_foreach (landmark_list, PrintLandmarkCb, NULL);
854 void search_poi(LocationMapObject* loc)
859 gchar *addr = g_strdup("4 N 2nd Street 95113");
860 LocationPOIFilter *filter = location_poi_filter_new();
861 LocationPOIPreference *pref = location_poi_pref_new();
863 location_poi_filter_set(filter, "CATEGORY", "restaurant");
865 location_poi_pref_set_max_result(pref, 5);
866 location_poi_pref_set_sort_by(pref, "name");
867 location_poi_pref_set_sort_order(pref, LOCATION_POI_PREF_SO_ASC);
869 ret = location_map_search_poi (loc, filter, addr, pref, poi_cb, loc, &req_id);
870 if (ret != LOCATION_ERROR_NONE) {
871 g_debug("Fail to get poi. Error[%d]", ret);
874 ret = location_map_cancel_poi_request (loc, req_id);
875 if (ret != LOCATION_ERROR_NONE) {
876 g_debug("Fail to cancel poi request. Err[%d]", ret);
879 location_poi_filter_free(filter);
880 location_poi_pref_free(pref);
885 int location_map_cancel_poi_request (LocationMapObject *obj, guint req_id);
888 * @brief Request a route service from service provider.
889 * @remarks refer #LocationRoute, #LocationRouteSegment and #LocationRouteStep
890 * @pre #location_map_new should be called before.
892 * @param [in] obj - a #LocationMapObject created by #location_map_new
893 * @param [in] origin - a #LocationPosition
894 * @param [in] destination - a #LocationPosition
895 * @param [in] waypoint - a list of #LocationPosition
896 * const LocationRoutePreference * pref, LocationRouteCB cb, gpointer user_data, guint * req_id);
897 * @param [in] pref - a #LocationRoutePreference created by #location_route_pref_new
898 * @param [in] cb - a #LocationRouteCB
899 * @param [in] user_data - a gpointer
900 * @param [out] req_id - a guint
903 * Please refer #LocationError for more information.
906 #include <location.h>
907 #include <location-map-service.h>
909 static void free_waypoint (gpointer data)
911 LocationPosition *pos = (LocationPosition *)data;
913 if (pos) location_position_free(pos);
916 static void __print_route_step (gpointer data, gpointer user_data)
918 g_printf("+++Step begin\n");
919 LocationRouteStep *step = (LocationRouteStep *)data;
921 const LocationPosition *start = location_route_step_get_start_point(step);
922 gdouble start_lat = 0;
923 gdouble start_lon = 0;
925 start_lat = start->latitude;
926 start_lon = start->longitude;
928 g_printf("Step start position NULL\n");
930 const LocationPosition *end = location_route_step_get_end_point(step);
934 end_lat = end->latitude;
935 end_lon = end->longitude;
937 g_printf("Step end postion NULL\n");
939 const gchar *inst = location_route_step_get_instruction(step);
941 g_printf("Step: start(%f/%f), end(%f/%f), instruction(%s)\n", start_lat, start_lon, end_lat, end_lon, inst);
943 g_printf("---Step end\n");
946 static void print_route_segment (gpointer data, gpointer user_data)
948 g_printf("++Segment begin\n");
949 LocationRouteSegment *seg = (LocationRouteSegment *)data;
950 gdouble seg_dist = location_route_segment_get_distance(seg);
951 glong seg_duration = location_route_segment_get_duration(seg);
952 const LocationPosition *start = location_route_segment_get_start_point(seg);
953 gdouble start_lat = 0;
954 gdouble start_lon = 0;
956 start_lat = start->latitude;
957 start_lon = start->longitude;
959 g_printf("Segment start postion NULL\n");
961 const LocationPosition *end = location_route_segment_get_end_point(seg);
965 end_lat = end->latitude;
966 end_lon = end->longitude;
968 g_printf("Segment end postion NULL\n");
970 g_printf("Segment info: Distance[%f], Duration[%ld], start(%f/%f), end(%f/%f)\n", seg_dist, seg_duration,
971 start_lat, start_lon, end_lat, end_lon);
973 GList *step_list = location_route_segment_get_route_step(seg);
974 GList *tmp_list = (GList *)step_list;
976 g_list_foreach(tmp_list, print_route_step, NULL);
978 g_printf("--Segment end\n");
982 static void print_route_list (gpointer data, gpointer user_data)
984 g_printf("+Route begin\n");
985 LocationRoute *route = (LocationRoute *)data;
987 const LocationPosition *start = location_route_get_origin(route);
988 gdouble start_lat = 0;
989 gdouble start_lon = 0;
991 start_lat = start->latitude;
992 start_lon = start->longitude;
994 g_printf("Route start position NULL\n");
996 const LocationPosition *end = location_route_get_destination(route);
1000 end_lat = end->latitude;
1001 end_lon = end->longitude;
1003 g_printf("Route end position NULL\n");
1005 g_printf("Route: start(%f/%f), end(%f/%f)\n", start_lat, start_lon, end_lat, end_lon);
1007 gdouble distance = location_route_get_total_distance(route);
1008 const gchar *dis_unit = location_route_get_distance_unit(route);
1009 glong duration = location_route_get_total_duration(route);
1010 const LocationBoundary *bound = location_route_get_bounding_box(route);
1011 if (bound && bound->type == LOCATION_BOUNDARY_RECT) {
1012 g_printf("RECT left top[%f-%f], right bottom[%f-%f]\n", bound->rect.left_top->latitude, bound->rect.left_top->longitude,
1013 bound->rect.right_bottom->latitude, bound->rect.right_bottom->longitude);
1015 g_printf("route boundary not exist, or not RECT\n");
1017 g_printf ("Distance[%f], Distance unit[%s], Duration[%ld]\n", distance, dis_unit, duration);
1019 GList *seg_list = location_route_get_route_segment(route);
1021 g_list_foreach(seg_list, print_route_segment, NULL);
1024 g_printf("-Route end\n");
1027 static void cb_route(LocationError error, guint req_id, GList * route_list, gchar * error_code, gchar * error_msg, gpointer userdata)
1029 if (error != LOCATION_ERROR_NONE) {
1030 g_printf("Failed :%d\n", error);
1034 g_printf("Success, poi_list[0x%x] user_data[0x%x] req_id[%d]\n", (unsigned int)route_list, (unsigned int)userdata, req_id);
1035 g_list_foreach (route_list, print_route_list, NULL);
1037 if (error_code && error_msg) {
1038 g_printf("cb_route: error_code[%s], error_msg[%s]\n", error_code, error_msg);
1042 int request_route(LocationMapObject *loc)
1045 LocationPosition *origin = location_position_new(0, 37.564263, 126.974676, 0, LOCATION_STATUS_2D_FIX); // Seoul city hall
1046 LocationPosition *destination = location_position_new(0, 37.557120, 126.992410, 0, LOCATION_STATUS_2D_FIX); // NamSan
1048 GList *waypoint = NULL;
1049 LocationPosition *via_pos = location_position_new(0, 37.560950, 126.986240, 0, LOCATION_STATUS_2D_FIX); // Wangsimli
1050 waypoint = g_list_append (waypoint, (gpointer)via_pos);
1052 LocationRoutePreference *pref = location_route_pref_new();
1053 gchar *type = g_strdup("FASTEST");
1054 location_route_pref_set_route_type(pref, type);
1056 ret = location_request_route(loc, origin, destination, waypoint, pref, cb_route, NULL, &req_id);
1057 if (ret != LOCATION_ERROR_NONE) {
1058 g_printf("Fail to search route by address. Error[%d]\n", ret);
1060 g_printf("Search Route successfully, req_id %d\n", req_id);
1064 g_list_free_full (waypoint, free_waypoint);
1065 location_position_free(origin);
1066 location_position_free(destination);
1067 location_route_pref_free(pref);
1073 int location_map_request_route (LocationMapObject *obj, LocationPosition *origin, LocationPosition *destination, GList *waypoint, const LocationRoutePreference * pref, LocationRouteCB cb, gpointer user_data, guint * req_id);
1076 * @brief Cancel the previous route request.
1078 * @pre #location_map_request_route should be called before.
1080 * @param [in] obj - a #LocationMapObject created by #location_map_new
1081 * @param [in] req_id - a route request id returned by location_map_search_route
1084 * Please refer #LocationError for more information.
1087 #include <location.h>
1088 #include <location-map-service.h>
1090 int cancel_route_request (LocationMapObject *loc, guint req_id)
1092 g_printf("cancel_route_request\n");
1094 int ret = LOCATION_ERROR_NONE;
1096 ret = location_map_cancel_route_request(loc, req_id);
1097 if (ret != LOCATION_ERROR_NONE) {
1098 g_printf("Fail to cancel route request. Error[%d]\n", ret);
1101 g_printf("location_map_cancel_route_request, req_id %d\n", req_id);
1106 int location_map_cancel_route_request (LocationMapObject *obj, guint req_id);
1109 * @brief Check wheither a map service is available on a service provider
1111 * @pre #location_map_new should be called before.
1113 * @param [in] obj - a #LocationMapObject created by #location_map_new
1114 * @param [in] type - a #LocationMapService
1116 * @retval TRUE if supported
1119 #include <location.h>
1120 #include <location-map-service.h>
1122 int check_map_service (LocationMapObject *loc)
1124 g_printf("check_map_service\n");
1126 gboolean is_supported = FALSE;
1128 is_supported = location_map_is_supported_provider_capability(loc, MAP_SERVICE_ROUTE_REQUEST_FEATURE_TO_AVOID);
1129 if (is_supported == TRUE) {
1130 g_printf("Map Service(MAP_SERVICE_ROUTE_REQUEST_FEATURE_TO_AVOID) is supported.\n");
1133 g_printf("Map Service(MAP_SERVICE_ROUTE_REQUEST_FEATURE_TO_AVOID) is not supported.\n");
1138 gboolean location_map_is_supported_provider_capability (LocationMapObject *obj, LocationMapServiceType type);
1141 * @brief Get Map service key on a service provider
1143 * @pre #location_map_new should be called before.
1145 * @param [in] obj - a #LocationMapObject created by #location_map_new
1146 * @param [in] type - a #LocationMapService
1148 * @retval a list of keys
1151 #include <location.h>
1152 #include <location-map-service.h>
1154 static void _print_keys(gpointer data)
1156 g_return_if_fail(data);
1157 gchar *key = (gchar *)data;
1159 g_printf("Key[%s] is available now\n", key);
1162 int get_map_service_key (LocationMapObject *loc)
1164 g_printf("check_map_service\n");
1168 keys = location_map_get_provider_capability_key(loc, MAP_SERVICE_ROUTE_REQUEST_FEATURE_TO_AVOID);
1170 g_list_foreach (keys, _print_keys, NULL);
1171 g_list_free_full (keys, g_free);
1174 g_printf("Map Service(MAP_SERVICE_ROUTE_REQUEST_FEATURE_TO_AVOID) does not have keys. Need to check whether its service is supported.\n");
1179 int location_map_get_provider_capability_key (LocationMapObject *obj, LocationMapServiceType type, GList **key);
1182 * @brief Get Map service Preference on a service provider
1184 * @pre #location_map_new should be called before.
1186 * @param [in] obj - a #LocationMapObject created by #location_map_new
1187 * @return #LocationMapPref
1188 * @retval a preference
1191 #include <location.h>
1192 #include <location-map-service.h>
1193 int get_map_service_pref (LocationMapObject loc)
1195 if (!loc) return -1;
1197 LocationMapPref *svc_pref = location_map_get_service_pref (loc);
1198 if (!svc_pref) return -1;
1200 gchar *name = location_map_pref_get_provider (svc_pref);
1201 gchar *unit = location_map_pref_get_distance_unit (svc_pref);
1202 gchar *language = location_map_pref_get_language (svc_pref);
1204 g_printf("provider [%s]: distance unit [%s], languange [%s]\n", name, unit, language);
1211 LocationMapPref *location_map_get_service_pref (LocationMapObject *obj);
1214 * @brief Set Map service preference on a service provider
1216 * @pre #location_map_new should be called before.
1218 * @param [in] obj - a #LocationMapObject created by #location_map_new
1219 * @param [in] pref = a #LocationMapPref
1221 * @retval TRUE if success
1224 #include <location.h>
1225 #include <location-map-service.h>
1227 int set_map_service_pref (LocationMapObject *loc)
1229 if (!loc) return -1;
1231 LocationMapPref *svc_pref = location_map_pref_new();
1232 location_map_pref_set_language (svc_pref, "en");
1233 location_map_pref_set_distance_unit (svc_pref, "MI");
1235 gboolean ret = location_map_set_service_pref (loc, svc_pref);
1237 location_map_pref_pref (svc_pref);
1240 location_map_pref_pref (svc_pref);
1245 gboolean location_map_set_service_pref (LocationMapObject *obj, LocationMapPref *pref);
1248 * @brief Get supported map providers
1249 * @remarks LocationMapObject should be created before.
1252 * @param [in] obj - #LocationMapObject
1254 * @retval a list of providers
1256 GList *location_map_get_supported_providers (LocationMapObject *obj);
1259 * @brief Get current default provider
1260 * @remarks LocationMapObject should be created before.
1263 * @param [in] obj - LocationMapObject
1265 * @retval provider name
1267 gchar *location_map_get_default_provider (LocationMapObject *obj);
1270 * @brief Set current provider
1271 * @remarks LocationMapObject should be created before.
1274 * @param [in] obj - LocationMapObject
1275 * @param [in] provider - gchar
1277 * @retval TRUE if success
1279 gboolean location_map_set_provider (LocationMapObject *obj, gchar *provider);
1287 #endif /* __LOCATION_MAP_SERVICE_H__ */