1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
/*
* libslp-location
*
* Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Youngae Kang <youngae.kang@samsung.com>, Yunhan Kim <yhan.kim@samsung.com>,
* Genie Kim <daejins.kim@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <glib.h>
#include <location.h>
static GMainLoop *loop = NULL;
static gboolean
exit_program (gpointer data)
{
g_main_loop_quit (loop);
g_debug ("Quit g_main_loop");
return FALSE;
}
static void
cb_service_enabled (GObject *self,
guint status,
gpointer userdata)
{
g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
}
static void
cb_service_disabled (GObject *self,
guint status,
gpointer userdata)
{
g_debug("cb_service_disabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
}
static void
cb_zone_in (GObject *self,
guint type,
gpointer position,
gpointer accuracy)
{
g_debug("cb_zone_in: type(%d)", type);
LocationPosition *pos = (LocationPosition*) position;
LocationAccuracy *acc = (LocationAccuracy*) accuracy;
g_debug ("ASYNC>> ZoneIn> Current position: time: %d, lat: %f, long: %f, alt: %f",
pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
}
static void
cb_zone_out (GObject *self,
guint type,
gpointer position,
gpointer accuracy)
{
g_debug("cb_zone_out: type(%d)", type);
LocationPosition *pos = (LocationPosition*) position;
LocationAccuracy *acc = (LocationAccuracy*) accuracy;
g_debug ("ASYNC>> ZoneOut> Current position: time: %d, lat: %f, long: %f, alt: %f",
pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
}
int
main (int argc, char *argv[])
{
LocationObject *loc = NULL;
location_init ();
loop = g_main_loop_new (NULL, TRUE);
loc = location_new (LOCATION_METHOD_GPS);
if (!loc) {
g_debug("location_new failed");
return -1;
}
LocationPosition *rb = location_position_new(0, 37.258, 127.056, 0, LOCATION_STATUS_2D_FIX);
LocationPosition *lt = location_position_new(0, 37.260, 127.054, 0, LOCATION_STATUS_2D_FIX);
LocationBoundary *bound = location_boundary_new_for_rect(lt, rb);
location_position_free (rb);
location_position_free (lt);
if (bound) {
g_object_set(loc, "boundary", bound, NULL);
location_boundary_free(bound);
} else g_warning("failed to location_boundary_new_for_rect()");
g_object_get(loc, "boundary", &bound, NULL);
if (bound) {
g_debug("Set property>> boundary> type: %d, (%f,%f),(%f,%f)",
bound->type,
bound->rect.right_bottom->latitude, bound->rect.right_bottom->longitude,
bound->rect.left_top->latitude, bound->rect.left_top->longitude);
location_boundary_free (bound);
} else g_warning("failed to set property> boundary");
g_signal_connect (loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc);
g_signal_connect (loc, "service-disabled", G_CALLBACK(cb_service_disabled), loc);
g_signal_connect (loc, "zone-in", G_CALLBACK(cb_zone_in), loc);
g_signal_connect (loc, "zone-out", G_CALLBACK(cb_zone_out), loc);
if( LOCATION_ERROR_NONE != location_start (loc) ){
g_debug("location_start failed");
return -1;
}
g_timeout_add_seconds (60, exit_program, NULL);
g_main_loop_run (loop);
location_stop (loc);
location_free (loc);
return 0;
}
|