f7b22694aeb5904eb1a83534f9aea0f8d2f6eca4
[framework/location/libslp-location.git] / tests / ips-test.c
1 /*
2  * libslp-location
3  *
4  * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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>
8  *
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
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  */
21
22 #include <glib.h>
23 #include <location/location.h>
24
25 int
26 main (int argc, char *argv[])
27 {
28         LocationObject *loc = NULL;
29
30         // If application is executed by AUL, this is not needed.
31         g_setenv("PKG_NAME", "com.samsung.ips-test", 1);
32
33         location_init ();
34
35         loc  = location_new (LOCATION_METHOD_IPS);
36         if (!loc) {
37                 g_debug("location_new failed");
38                 return -1;
39         }
40
41         LocationMethod method = LOCATION_METHOD_NONE;
42         g_object_get(loc, "method", &method, NULL);
43         g_debug("Get property>> method:%d", method);
44
45         LocationAccuracy *acc = NULL;
46         LocationPosition *pos = NULL;
47         LocationAddress *addr = NULL;
48
49         if (LOCATION_ERROR_NONE == location_get_position (loc, &pos, &acc)) {
50                 g_debug ("SYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
51                         pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
52                 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
53                         acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
54                 location_position_free(pos);
55                 location_accuracy_free(acc);
56         } else g_warning ("SYNC>> Current position> failed");
57         if (LOCATION_ERROR_NONE == location_get_address(loc, &addr, &acc)) {
58                 g_debug ("SYNC>> Current address> %s %s %s %s %s %s %s",
59                         addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code);
60                 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
61                 location_address_free(addr);
62                 location_accuracy_free(acc);
63         } else g_warning ("SYNC>> Current address> failed");
64
65         g_object_get(loc, "last-position", &pos, NULL);
66         if (pos) {
67                 g_debug ("Get property>> last-position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
68                         pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
69                 location_position_free(pos);
70         } else  g_warning("failed to get property> last-position");
71
72         location_free (loc);
73
74         return 0;
75 }