Tizen 2.0 Release
[framework/api/geocoder.git] / test / geocoder_test.c
1 /*
2  * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <glib.h>
21 #include <geocoder.h>
22
23 geocoder_h geocoder;
24
25 static void  get_addr_cb(geocoder_error_e result, const char *building_number, const char *postal_code, const char *street, const  char *city, const char *district, const char *state, const char *country_code, void *user_data)
26 {
27                 printf("get_addr_cb() ===> building number: %s, postal code: %s, street: %s, city: %s, district:  %s, state: %s, country code: %s\n", building_number,postal_code,street,city,district,state,country_code);
28 }
29
30 static bool  get_pos_cb(geocoder_error_e result, double latitude, double longitude, void *user_data)
31 {
32                 printf ("get_pos_cb() ===> latitude  : %g, longitude : %g\n",latitude, longitude);
33                 return true;
34 }
35
36 int geocoder_test()
37 {
38         int ret;
39         if (geocoder ==NULL)
40         {
41                 ret = geocoder_create(&geocoder);
42                 if(ret != GEOCODER_ERROR_NONE)
43                 {
44                         printf ("geocoder_create return error : %d=n", ret);
45                 }
46         }
47
48         ret = geocoder_get_address_from_position(geocoder,37.258,127.056,get_addr_cb, NULL);
49         if(ret != GEOCODER_ERROR_NONE)
50         {
51                 printf ("geocoder_get_address_from_position return error : %d\n", ret);
52         }
53         return 1;
54 }
55
56 int reverse_geocoder_test()
57 {
58         int ret;
59         if (geocoder ==NULL)
60         {
61                 ret = geocoder_create(&geocoder);
62                 if(ret != GEOCODER_ERROR_NONE)
63                 {
64                         printf ("geocoder_create return error : %d=n", ret);
65                 }
66         }
67         char *address="suwon";
68
69         ret = geocoder_foreach_positions_from_address (geocoder,address, get_pos_cb, (void*)geocoder);
70         if(ret != GEOCODER_ERROR_NONE)
71         {
72                 printf ("geocoder_foreach_positions_from_address_sync return error : %d\n", ret);
73         }
74         return 1;
75 }
76
77
78 static GMainLoop *loop = NULL;
79
80 static gboolean exit_program (gpointer data)
81 {
82         g_main_loop_quit (loop);
83         printf("Quit g_main_loop\n");
84         return FALSE;
85 }
86
87
88 int main(int argc, char ** argv)
89 {
90         loop =g_main_loop_new (NULL, TRUE);
91         g_setenv("PKG_NAME", "org.tizen.capi-location-geocoder-test", 1);
92
93         geocoder_test();
94         reverse_geocoder_test();
95         g_timeout_add_seconds(30, exit_program, NULL);
96         g_main_loop_run (loop);
97         
98         return 0;
99 }
100