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 #include <gconf/gconf-client.h>
23 #include <location/location.h>
25 static GMainLoop *loop = NULL;
27 #define GCONF_PROXY_MODE "/system/proxy/mode"
28 #define GCONF_HTTP_PROXY_HOST "/system/http_proxy/host"
29 #define GCONF_HTTP_PROXY_PORT "/system/http_proxy/port"
30 #define ENV_HTTP_PROXY "http_proxy"
33 exit_program (gpointer data)
35 g_main_loop_quit (loop);
36 g_debug ("Quit g_main_loop");
41 cb_address (LocationError error,
42 LocationAddress *addr,
43 LocationAccuracy *acc,
46 if (error != LOCATION_ERROR_NONE) {
47 g_debug("cb_address failed: error=%d\n", error);
50 g_debug ("ASYNC>> location_get_address_async> %s %s %s %s %s %s %s",
51 addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code);
52 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
56 cb_service_disabled (GObject *self,
60 g_debug("cb_service_disabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
64 cb_position_from_address (LocationError error, LocationPosition *pos, LocationAccuracy *acc, gpointer userdata)
66 if (error != LOCATION_ERROR_NONE) {
67 g_debug("cb_position_from_address failed: error=%d\n", error);
70 g_debug ("ASYNC>> location_get_position_from_address_async> time: %d, lat: %f, long: %f, alt: %f, status: %d",
71 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
72 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
76 cb_position_from_freeformed_address (LocationError error, LocationPosition *pos, LocationAccuracy *acc, gpointer userdata)
78 if (error != LOCATION_ERROR_NONE) {
79 g_debug("cb_position_from_freeformed_address failed: error=%d\n", error);
82 g_debug ("ASYNC>> location_get_position_from_freeformed_address_async> time: %d, lat: %f, long: %f, alt: %f, status: %d",
83 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
84 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
88 cb_address_from_position (LocationError error, LocationAddress *addr, LocationAccuracy *acc, gpointer userdata)
90 if (error != LOCATION_ERROR_NONE) {
91 g_debug("cb_address_from_position failed: error=%d\n", error);
94 g_debug ("ASYNC>> location_get_address_from_position_async> %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);
100 cb_service_enabled (GObject *self,
104 g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
106 LocationAddress *addr = NULL;
107 LocationAccuracy *acc = NULL;
108 LocationObject *loc = (LocationObject*)userdata;
110 LocationError err = location_get_address(loc, &addr, &acc);
111 if (LOCATION_ERROR_NONE == err) {
112 g_debug ("SYNC>> location_get_address() success> %s %s %s %s %s %s %s",
113 addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code);
114 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
115 location_address_free(addr);
116 location_accuracy_free(acc);
117 } else g_warning ("SYNC>> location_get_address() failed> error code:%d", err);
119 err = location_get_address_async(loc, cb_address, loc);
120 if (LOCATION_ERROR_NONE == err) g_debug("location_get_address_async() success");
121 else g_warning ("location_get_address_async() failed> error code:%d", err);
125 async_request (gpointer loc)
127 LocationAddress *addr = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113");
128 LocationError err = location_get_position_from_address_async(loc, addr, cb_position_from_address, loc);
129 if (LOCATION_ERROR_NONE == err)
130 g_debug("location_get_position_from_address_async() success");
131 else g_warning ("location_get_position_from_address_async() failed> error code:%d", err);
132 location_address_free (addr);
134 gchar *addr_str = g_strdup("4 N 2nd Street 95113");
135 err = location_get_position_from_freeformed_address_async(loc, addr_str, cb_position_from_freeformed_address, loc);
136 if (LOCATION_ERROR_NONE == err)
137 g_debug("location_get_position_from_freeformed_address_async() success");
138 else g_warning ("location_get_position_from_freeformed_address_async() failed> error code:%d", err);
141 LocationPosition *pos = location_position_new (0, 37.3322, -121.8720, 0, LOCATION_STATUS_2D_FIX);
142 err = location_get_address_from_position_async(loc, pos, cb_address_from_position, loc);
143 if (LOCATION_ERROR_NONE == err)
144 g_debug("location_get_address_from_position_async() success");
145 else g_warning ("location_get_address_from_position_async() failed> error code:%d", err);
146 location_position_free (pos);
151 main (int argc, char *argv[])
153 LocationObject *loc = NULL;
155 // If application is executed by AUL, this is not needed.
156 g_setenv("PKG_NAME", "org.tizen.address-sample", 1);
160 loop = g_main_loop_new (NULL, TRUE);
162 loc = location_new (LOCATION_METHOD_GPS);
164 g_warning("location_new failed");
167 LocationPosition *pos = NULL;
168 LocationAccuracy *acc = NULL;
169 LocationAddress *addr = NULL;
171 addr = location_address_new ("1", "Post Street", NULL, "san jose", "ca", NULL, "95113");
172 LocationError err = location_get_position_from_address(loc, addr, &pos, &acc);
173 if (LOCATION_ERROR_NONE == err) {
174 g_debug ("SYNC>> location_get_position_from_address() success> time: %d, lat: %f, long: %f, alt: %f, status: %d",
175 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
176 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
177 location_position_free (pos);
178 location_accuracy_free (acc);
179 } else g_warning ("SYNC>>>location_get_position_from_address() failed> error code:%d", err);
180 location_address_free (addr);
182 char* addr_str = g_strdup("4 N 2nd Street 95113");
183 err = location_get_position_from_freeformed_address(loc, addr_str, &pos, &acc);
184 if (LOCATION_ERROR_NONE == err) {
185 g_debug ("SYNC>> location_get_position_from_freeformed_address() success> time: %d, lat: %f, long: %f, alt: %f, status: %d",
186 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
187 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
188 location_position_free (pos);
189 location_accuracy_free (acc);
190 } else g_warning ("SYNC>> location_get_position_from_freeformed_address() failed> error code:%d", err);
193 pos = location_position_new (0, 37.3322, -121.8720, 0, LOCATION_STATUS_2D_FIX);
194 err = location_get_address_from_position(loc, pos, &addr, &acc);
195 if (LOCATION_ERROR_NONE == err) {
196 g_debug ("SYNC>> location_get_address_from_position() success> %s %s %s %s %s %s %s",
197 addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code);
198 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
199 location_address_free(addr);
200 location_accuracy_free(acc);
201 } else g_warning ("SYNC>> location_get_address_from_position() failed> error code:%d", err);
202 location_position_free (pos);
204 g_signal_connect (loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc);
205 g_signal_connect (loc, "service-disabled", G_CALLBACK(cb_service_disabled), loc);
207 g_timeout_add_seconds (3, async_request, loc);
208 if( LOCATION_ERROR_NONE != location_start (loc) ){
209 g_debug("location_start failed");
213 g_timeout_add_seconds (60, exit_program, NULL);
214 g_main_loop_run (loop);