Release Tizen2.0 beta
[framework/location/libslp-location.git] / tests / cps-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.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.cps-test", 1);
32
33         location_init ();
34
35         loc  = location_new (LOCATION_METHOD_CPS);
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
48         if (LOCATION_ERROR_NONE == location_get_position (loc, &pos, &acc)) {
49                 g_debug ("SYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
50                         pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
51                 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
52                         acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
53                 location_position_free(pos);
54                 location_accuracy_free(acc);
55         } else g_warning ("SYNC>> Current position> failed");
56
57         g_object_get(loc, "last-position", &pos, NULL);
58         if (pos) {
59                 g_debug ("Get property>> last-position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
60                         pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
61                 location_position_free(pos);
62         } else  g_warning("failed to get property> last-position");
63
64         location_free (loc);
65         return 0;
66 }
67