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.
25 static GMainLoop *loop = NULL;
28 cb_service_updated (GObject *self,
34 g_debug("cb_service_updated: type(%d) userdata(0x%x)", type, (unsigned int)userdata);
36 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
38 case POSITION_UPDATED: {
39 LocationPosition *pos = (LocationPosition*) data;
40 g_debug ("ASYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
41 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
42 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
43 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
46 case VELOCITY_UPDATED: {
47 LocationVelocity *vel = (LocationVelocity*) data;
48 g_debug ("ASYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f",
49 vel->timestamp, vel->speed, vel->direction, vel->climb);
50 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
51 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
55 g_warning ("ASYNC>> Undefined update type");
61 cb_service_enabled (GObject *self,
65 g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
67 LocationObject *loc = (LocationObject*)userdata;
68 LocationAccuracy *acc = NULL;
69 LocationPosition *pos = NULL;
70 LocationVelocity *vel = NULL;
71 LocationAddress *addr = NULL;
72 LocationMethod method;
74 g_object_get(loc, "method", &method, NULL);
75 g_debug("Get property>> method:%d", method);
77 if (LOCATION_ERROR_NONE == location_get_position (loc, &pos, &acc)) {
78 g_debug ("SYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
79 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
80 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
81 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
82 location_position_free(pos);
83 location_accuracy_free(acc);
84 } else g_warning ("SYNC>> Current position> failed");
85 if (LOCATION_ERROR_NONE == location_get_velocity (loc, &vel, &acc)) {
86 g_debug ("SYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f",
87 vel->timestamp, vel->speed, vel->direction, vel->climb);
88 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
89 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
90 location_velocity_free(vel);
91 location_accuracy_free(acc);
92 } else g_warning ("SYNC>> Current velocity> failed");
93 if (LOCATION_ERROR_NONE == location_get_address(loc, &addr, &acc)) {
94 g_debug ("SYNC>> Current address> %s %s %s %s %s %s %s",
95 addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code);
96 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
97 location_address_free(addr);
98 location_accuracy_free(acc);
99 } else g_warning ("SYNC>> Current address> failed");
103 cb_service_disabled (GObject *self,
107 g_debug("cb_service_disabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
111 cb_zone_in (GObject *self,
116 g_debug("cb_zone_in: type(%d)", type);
117 LocationPosition *pos = (LocationPosition*) position;
118 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
120 g_debug ("ASYNC>> ZoneIn> Current position: time: %d, lat: %f, long: %f, alt: %f",
121 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
122 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
123 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
127 cb_zone_out (GObject *self,
132 g_debug("cb_zone_out: type(%d)", type);
133 LocationPosition *pos = (LocationPosition*) position;
134 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
136 g_debug ("ASYNC>> ZoneOut> Current position: time: %d, lat: %f, long: %f, alt: %f",
137 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
138 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
139 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
143 main (int argc, char *argv[])
145 LocationObject *loc = NULL;
147 // If application is executed by AUL, this is not needed.
148 g_setenv("PKG_NAME", "com.samsung.hybrid-test", 1);
152 loop = g_main_loop_new (NULL, TRUE);
154 loc = location_new (LOCATION_METHOD_HYBRID);
156 g_debug("location_new failed");
160 LocationMethod method = LOCATION_METHOD_NONE;
161 g_object_get(loc, "method", &method, NULL);
162 g_debug("Get property>> method:%d", method);
164 LocationBoundary *bound = NULL;
165 g_object_get(loc, "boundary", &bound, NULL);
167 g_debug("Get property>> boundary> type: %d", bound->type);
168 location_boundary_free (bound);
169 } else g_warning("failed to get property> boundary");
171 LocationPosition *rb = location_position_new(0, 37.258, 127.056, 0, LOCATION_STATUS_2D_FIX);
172 LocationPosition *lt = location_position_new(0, 37.260, 127.054, 0, LOCATION_STATUS_2D_FIX);
173 bound = location_boundary_new_for_rect(lt, rb);
174 location_position_free (rb);
175 location_position_free (lt);
177 g_object_set(loc, "boundary", bound, NULL);
178 location_boundary_free(bound);
179 } else g_warning("failed to location_boundary_new_for_rect()");
180 g_object_get(loc, "boundary", &bound, NULL);
182 g_debug("Set property>> boundary> type: %d, (%f,%f),(%f,%f)",
184 bound->rect.right_bottom->latitude, bound->rect.right_bottom->longitude,
185 bound->rect.left_top->latitude, bound->rect.left_top->longitude);
186 location_boundary_free (bound);
187 } else g_warning("failed to set property> boundary");
189 g_signal_connect (loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc);
190 g_signal_connect (loc, "service-disabled", G_CALLBACK(cb_service_disabled), loc);
191 g_signal_connect (loc, "service-updated", G_CALLBACK(cb_service_updated), loc);
192 g_signal_connect (loc, "zone-in", G_CALLBACK(cb_zone_in), loc);
193 g_signal_connect (loc, "zone-out", G_CALLBACK(cb_zone_out), loc);
195 if (LOCATION_ERROR_NONE != location_start (loc)) {
196 g_debug("location_start failed");
200 g_main_loop_run (loop);
204 LocationPosition *pos = NULL;
205 g_object_get(loc, "last-position", &pos, NULL);
207 g_debug ("Get property>> last-position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
208 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
209 location_position_free(pos);
210 } else g_warning("failed to get property> last-position");