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 #include <location/location.h>
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;
73 if (LOCATION_ERROR_NONE == location_get_position (loc, &pos, &acc)) {
74 g_debug ("SYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
75 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
76 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
77 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
78 location_position_free(pos);
79 location_accuracy_free(acc);
80 } else g_warning ("SYNC>> Current position> failed");
81 if (LOCATION_ERROR_NONE == location_get_velocity (loc, &vel, &acc)) {
82 g_debug ("SYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f",
83 vel->timestamp, vel->speed, vel->direction, vel->climb);
84 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
85 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
86 location_velocity_free(vel);
87 location_accuracy_free(acc);
88 } else g_warning ("SYNC>> Current velocity> failed");
89 if (LOCATION_ERROR_NONE == location_get_address(loc, &addr, &acc)) {
90 g_debug ("SYNC>> Current address> %s %s %s %s %s %s %s",
91 addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code);
92 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
93 location_address_free(addr);
94 location_accuracy_free(acc);
95 } else g_warning ("SYNC>> Current address> failed");
99 cb_service_disabled (GObject *self,
103 g_debug("cb_service_disabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
107 cb_zone_in (GObject *self,
112 g_debug("cb_zone_in: type(%d)", type);
113 LocationPosition *pos = (LocationPosition*) position;
114 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
116 g_debug ("ASYNC>> ZoneIn> Current position: time: %d, lat: %f, long: %f, alt: %f",
117 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
118 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
119 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
123 cb_zone_out (GObject *self,
128 g_debug("cb_zone_out: type(%d)", type);
129 LocationPosition *pos = (LocationPosition*) position;
130 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
132 g_debug ("ASYNC>> ZoneOut> Current position: time: %d, lat: %f, long: %f, alt: %f",
133 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
134 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
135 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
139 main (int argc, char *argv[])
141 LocationObject *loc = NULL;
143 // If application is executed by AUL, this is not needed.
144 g_setenv("PKG_NAME", "com.samsung.wps-test", 1);
148 loop = g_main_loop_new (NULL, TRUE);
150 loc = location_new (LOCATION_METHOD_WPS);
152 g_debug("location_new failed");
156 LocationMethod method = LOCATION_METHOD_NONE;
157 g_object_get(loc, "method", &method, NULL);
158 g_debug("Get property>> method:%d", method);
160 LocationBoundary *bound = NULL;
161 g_object_get(loc, "boundary", &bound, NULL);
163 g_debug("Get property>> boundary> type: %d", bound->type);
164 location_boundary_free (bound);
165 } else g_warning("failed to get property> boundary");
167 LocationPosition *rb = location_position_new(0, 37.255, 127.056, 0, LOCATION_STATUS_2D_FIX);
168 LocationPosition *lt = location_position_new(0, 37.260, 127.050, 0, LOCATION_STATUS_2D_FIX);
169 bound = location_boundary_new_for_rect(lt, rb);
170 location_position_free (rb);
171 location_position_free (lt);
173 g_object_set(loc, "boundary", bound, NULL);
174 location_boundary_free(bound);
175 } else g_warning("failed to location_boundary_new_for_rect()");
176 g_object_get(loc, "boundary", &bound, NULL);
178 g_debug("Set property>> boundary> type: %d, (%f,%f),(%f,%f)",
180 bound->rect.right_bottom->latitude, bound->rect.right_bottom->longitude,
181 bound->rect.left_top->latitude, bound->rect.left_top->longitude);
182 location_boundary_free (bound);
183 } else g_warning("failed to set property> boundary");
185 g_signal_connect (loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc);
186 g_signal_connect (loc, "service-disabled", G_CALLBACK(cb_service_disabled), loc);
187 g_signal_connect (loc, "service-updated", G_CALLBACK(cb_service_updated), loc);
188 g_signal_connect (loc, "zone-in", G_CALLBACK(cb_zone_in), loc);
189 g_signal_connect (loc, "zone-out", G_CALLBACK(cb_zone_out), loc);
191 if (LOCATION_ERROR_NONE != location_start (loc)) {
192 g_debug("location_start failed");
196 g_main_loop_run (loop);
200 LocationPosition *pos = NULL;
201 g_object_get(loc, "last-position", &pos, NULL);
203 g_debug ("Get property>> last-position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
204 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
205 location_position_free(pos);
206 } else g_warning("failed to get property> last-position");