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.
22 #ifndef __LOCATION_BOUNDARY_H_
23 #define __LOCATION_BOUNDARY_H_
25 #include <location/location-types.h>
26 #include <location/location-position.h>
29 * @file location-boundary.h
30 * @brief This file contains the definitions, structures, and functions related to boundary information.
31 * @addtogroup LocationTypes
39 * The type of the @location_boundary_foreach function of #LocationObject
41 typedef void (*LocationBoundaryFunc) (LocationBoundary *boundary, gpointer user_data);
44 * @brief This represents used geographical type, and supports rectangle or circle area.
47 LOCATION_BOUNDARY_NONE = 0, ///< Undefined geographical area type.
48 LOCATION_BOUNDARY_RECT, ///< Rectangular geographical area type.
49 LOCATION_BOUNDARY_CIRCLE, ///< Circle geographical area type.
50 LOCATION_BOUNDARY_POLYGON ///< Polygon geographical area type.
51 } LocationBoundaryType;
54 * @brief This represents a rectangular geographical area.
57 LocationPosition* left_top; ///< The left top position of rectangle.
58 LocationPosition* right_bottom; ///< The right bottom position of rectangle.
62 * @brief This represents a circle geographical area with center geographic position and radius.
65 LocationPosition* center; ///< The center position of a circle.
66 gdouble radius; ///< The radius of a circle.
70 * @brief This represents a polygon geographical area.
73 GList *position_list; ///< The collection of positions
77 * @brief This represents boundary information such as rectangular or circle area.
79 struct _LocationBoundary{
80 LocationBoundaryType type; ///< The boundary type of this information.
82 LocationRect rect; ///< The geographical information of a rectangle.
83 LocationCircle circle; ///< The geographical information of a circle.
84 LocationPolygon polygon; ///< The geographical information of a polygon.
88 GType location_boundary_get_type (void);
89 #define LOCATION_TYPE_BOUNDARY (location_boundary_get_type ())
92 * @brief Create a rectangular type of new #LocationBoundary with given information.
94 * @pre #location_init should be called before.\n
96 * @param [in] left_top - left top position.
97 * @param [in] right_bottom - right bottom position.
98 * @return a new #LocationBoundary
99 * @retval NULL if error occured
101 LocationBoundary *location_boundary_new_for_rect (LocationPosition *left_top, LocationPosition *right_bottom);
104 * @brief Create a circle type of new #LocationBoundary with given information.
106 * @pre #location_init should be called before.\n
108 * @param [in] center - center position.
109 * @param [in] radius - radius.
110 * @return a new #LocationBoundary
111 * @retval NULL if error occured
113 LocationBoundary *location_boundary_new_for_circle (LocationPosition *center, gdouble radius);
116 * @brief Create a polygon type of new #LocationBoundary with given information.
118 * @pre #location_init should be called before.\n
120 * @param [in] position_list - the list of positions.
121 * @return a new #LocationBoundary
122 * @retval NULL if error occured
124 LocationBoundary *location_boundary_new_for_polygon(GList *position_list);
127 * @brief Free a #LocationBoundary.
129 * @pre #location_init should be called before.\n
131 * @param [in] boundary - a #LocationBoundary.
134 void location_boundary_free (LocationBoundary *boundary);
137 * @brief Makes a copy of #LocationBoundary
139 * @pre #location_init should be called before.\n
141 * @param [in] boundary - a #LocationBoundary
142 * @return a new #LocationBoundary
143 * @retval NULL if error occured
145 LocationBoundary *location_boundary_copy (const LocationBoundary* boundary);
149 * Add Boundary on LocationFW.
150 * You should call this fuction when you want to receive a crossing signal(zone-in/zone-out) from #LocationBoundary.
151 * @remarks It supports multi-boundaries. \n
152 However a duplicated boundary would not be allowed.
154 * #location_new should be called before.\n
156 * @param [in] obj - a #LocationObject
157 * @param [in] boundary - a #LocationBoundary
160 * Please refer #LocationError for more information.
163 #include <location.h>
165 static void cb_zone_in (GObject *self, guint type, gpointer position, gpointer accuracy)
167 g_printf ("[zone-in] position - lat: %f, long: %f", position->latitude, position->longitude);
170 static void cb_zone_out (GObject *self, guint type, gpointer position, gpointer accuracy)
172 g_printf ("[zone-out] position - lat: %f, long: %f", position->latitude, position->longitude);
175 void location_test_boundary_add(LocationObject *loc)
177 LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX);
178 LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX);
180 LoationBoundary *boundary = location_boundary_new_for_rect (lt, rb);
182 ret = location_boundary_add(loc, boundary);
184 g_signal_connect(loc, "zone-in", G_CALLBACK(cb_zone_in), NULL);
185 g_siganl_connect(loc, "zone-out", G_CALLBACK(cb_zone_out), NULL);
187 location_position_free(rb);
188 location_position_free(lt);
192 int location_boundary_add(const LocationObject *obj, const LocationBoundary *boundary);
196 * Remove Boundary on LocationFW.
197 * You should call this function when you don't want to receive a crossing signal(zone-in/zone-out) from #LocationBoundary any more.
198 * @remarks It supports multi-boundaries.
200 * #location_init should be called before.\n
202 * @param [in] obj - a #LocationObject
203 * @param [in] boundary - a #LocationBoundary
207 * Please refer #LocationError for more information.
210 #include <location.h>
212 void location_test_boundary_remove(LocationObject *loc)
215 LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX);
216 LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX);
218 LoationBoundary *boundary = location_boundary_new_for_rect (lt, rb);
220 ret = location_boundary_remove(loc, boundary);
222 location_position_free(rb);
223 location_position_free(lt);
228 int location_boundary_remove(const LocationObject *obj, const LocationBoundary *boundary);
232 * Call a function for each element of a Boundary list.
235 * #location_init should be called before.\n
237 * @param [in] obj - a #LocationObject
238 * @param [in] func - a #LocationBoundaryFunc
239 * @param [in] user_data - a #void
243 * Please refer #LocationError for more information.
246 #include <location.h>
248 static void remove_boundary(LocationBoundary *boundary, void *user_data)
250 LocationBoundary *loc = (LocationBoundary *) user_data;
251 if (loc == NULL || boundary == NULL) return;
253 location_boundary_remove(loc, boundary);
256 void location_test_boundary_foreach(LocationObject *loc)
258 int ret = location_boundary_foreach(loc, remove_boundary, loc);
262 int location_boundary_foreach(const LocationObject *obj, LocationBoundaryFunc func, gpointer user_data);
266 * @brief Check if #LocationPosition is inside #LocationBoundary.
268 * @pre #location_init should be called before.\n
269 * @post None.* @param [in] boundary - a #LocationBoundary
270 * @param [in] position - a #LocationPosition
274 * FALSE - if outside\n
277 #include <location.h>
279 void location_test_boundary_if_inside(LocationObject *loc, LocationBoundary *boundary)
281 gboolean is_inside = FALSE;
282 LocationPosition* position = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX);
283 is_inside = location_boundary_if_inside(boundary, position);
284 if (is_inside == TRUE) g_printf("The position is inside of the boundary\n");
285 else g_printf("The position is outside of the boundary\n");
291 gboolean location_boundary_if_inside (LocationBoundary *boundary, LocationPosition *position);