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.
28 #include <location-map-service.h>
29 #include <location-map-service-ext.h>
30 #include <geoclue/geoclue-poi.h>
31 #include <geoclue/geoclue-landmark.h>
33 #include "location-osm.h"
34 #include "location-osm-poi.h"
36 static int g_req_id = 0;
39 _get_lang (gchar country_code[3], gchar lang_code[3])
41 if (!country_code || !lang_code) return;
42 gchar* langset = vconf_get_str(VCONFKEY_LANGSET);
43 MOD_LOGW("getenv: %s", langset);
49 country_code[0] = 'U';
50 country_code[1] = 'S';
51 country_code[2] = '\0';
53 gchar* langset_upper = g_ascii_strup(langset, -1);
54 lang_code[0] = langset_upper[0];
55 lang_code[1] = langset_upper[1];
57 country_code[0] = langset_upper[3];
58 country_code[1] = langset_upper[4];
59 country_code[2] = '\0';
60 g_free(langset_upper);
62 MOD_LOGW("Language: %s, Country: %s", lang_code, country_code);
66 _free_landmark(gpointer data)
68 g_return_if_fail (data);
70 LocationLandmark *landmark = (LocationLandmark *)data;
71 location_landmark_free(landmark);
76 _poi_callback(GeocluePoi *poi, int count, GPtrArray *landmark, GError *error, gpointer userdata)
78 OsmHandleData *data = (OsmHandleData *)userdata;
80 g_return_if_fail(data);
81 g_return_if_fail(data->poi_cb);
83 int req_id = data->req_id;
84 int err = LOCATION_ERROR_NONE;
85 GValueArray *vals = NULL;
86 GList *landmark_list = NULL;
87 LocationLandmark *land = NULL;
88 GeoclueLandmark landmark_data = {0, };
89 LocationBoundary *bounding_box = NULL;
90 LocationPosition *left_top = NULL;
91 LocationPosition *right_bottom = NULL;
94 if (!landmark || error) {
95 MOD_LOGE("Landmark[%p] is NULL or Error occurs", landmark);
96 err = LOCATION_ERROR_UNKNOWN;
99 MOD_LOGE("Count [%d]", count);
100 for (; idx < count; idx++) {
101 vals = (GValueArray *) g_ptr_array_index(landmark, idx);
106 landmark_data.id = g_value_get_int (g_value_array_get_nth(vals, 0));
107 landmark_data.rank = g_value_get_int (g_value_array_get_nth(vals, 1));
108 landmark_data.lat = g_value_get_double (g_value_array_get_nth(vals, 2));
109 landmark_data.lon = g_value_get_double (g_value_array_get_nth(vals, 3));
110 landmark_data.boundary_left = g_value_get_double (g_value_array_get_nth(vals, 4));
111 landmark_data.boundary_top = g_value_get_double (g_value_array_get_nth(vals, 5));
112 landmark_data.boundary_right = g_value_get_double (g_value_array_get_nth(vals, 6));
113 landmark_data.boundary_bottom = g_value_get_double (g_value_array_get_nth(vals, 7));
114 landmark_data.name = g_value_dup_string (g_value_array_get_nth(vals, 8));
115 landmark_data.icon = g_value_dup_string (g_value_array_get_nth(vals, 9));
116 landmark_data.house = g_value_dup_string (g_value_array_get_nth(vals, 10));
117 landmark_data.road = g_value_dup_string (g_value_array_get_nth(vals, 11));
118 landmark_data.village = g_value_dup_string (g_value_array_get_nth(vals, 12));
119 landmark_data.suburb = g_value_dup_string (g_value_array_get_nth(vals, 13));
120 landmark_data.postcode = g_value_dup_string (g_value_array_get_nth(vals, 14));
121 landmark_data.city = g_value_dup_string (g_value_array_get_nth(vals, 15));
122 landmark_data.county = g_value_dup_string (g_value_array_get_nth(vals, 16));
123 landmark_data.country = g_value_dup_string (g_value_array_get_nth(vals, 17));
124 landmark_data.country_code = g_value_dup_string (g_value_array_get_nth(vals, 18));
126 land = location_landmark_new();
128 location_landmark_set_id (land, (guint)landmark_data.id);
129 location_landmark_set_priority(land, (guint)landmark_data.rank);
130 location_landmark_set_position (land, location_position_new (0, landmark_data.lat, landmark_data.lon, 0.0, LOCATION_STATUS_2D_FIX));
132 location_landmark_set_name (land, landmark_data.name);
133 location_landmark_set_address (land, location_address_new (NULL, landmark_data.house, landmark_data.village, landmark_data.city, landmark_data.county, landmark_data.country_code, landmark_data.postcode));
134 location_landmark_set_property (land, "ICON", landmark_data.icon);
136 if (!landmark_data.boundary_left || landmark_data.boundary_top || landmark_data.boundary_right || landmark_data.boundary_bottom) {
137 left_top = location_position_new (0, landmark_data.boundary_left, landmark_data.boundary_top, 0.0, LOCATION_STATUS_2D_FIX);
138 right_bottom = location_position_new (0, landmark_data.boundary_right, landmark_data.boundary_bottom, 0.0, LOCATION_STATUS_2D_FIX);
139 bounding_box = location_boundary_new_for_rect (left_top, right_bottom);
141 location_landmark_set_bounding_box (land, bounding_box);
142 location_boundary_free(bounding_box);
145 if (left_top) location_position_free (left_top);
146 if (right_bottom) location_position_free (right_bottom);
154 landmark_list = g_list_append (landmark_list, land);
158 MOD_LOGW ("Calling LocationPOICB");
159 data->poi_cb (err, req_id, landmark_list, NULL, NULL, data->userdata);
161 g_list_free_full (landmark_list, _free_landmark);
165 osm_search_poi_by_position(OsmHandle *osm,
166 const LocationPOIFilter *filter,
167 const LocationPosition *position,
168 const LocationMapPref *svc_pref,
169 const LocationPOIPreference *pref,
171 const gpointer user_data,
174 int left = 0.0, top = 0.0, right = 0.0, bottom = 0.0;
175 *req_id = ++g_req_id;
177 OsmHandleData *data = g_new0 (OsmHandleData, 1);
178 data->req_id = *req_id;
180 data->userdata = user_data;
182 gchar *keyword = NULL, *lang = NULL, *country_code = NULL;
185 keyword = location_poi_filter_get(filter, "KEYWORD");
187 MOD_LOGW("OSM supports only keyword filter.");
188 return LOCATION_ERROR_PARAMETER;
192 lang = location_map_pref_get_language (svc_pref);
193 country_code = location_map_pref_get_country(svc_pref);
194 max_result = location_poi_pref_get_max_result(pref);
196 geoclue_poi_search_by_position_async (osm->poi, keyword, lang, country_code, max_result, left, top, right, bottom, _poi_callback, data);
198 return LOCATION_ERROR_NONE;
202 osm_search_poi_by_area(OsmHandle *osm,
203 const LocationPOIFilter *filter,
204 const LocationBoundary *boundary,
205 const LocationMapPref *svc_pref,
206 const LocationPOIPreference *pref,
208 const gpointer user_data,
211 *req_id = ++g_req_id;
213 OsmHandleData *data = g_new0 (OsmHandleData, 1);
215 gchar sys_country[3] = {0, }, sys_lang[3] = {0, };
216 gchar *keyword = NULL, *lang = NULL, *country_code = NULL;
218 gdouble left = 0.0, top = 0.0, right = 0.0, bottom = 0.0;
220 data->req_id = *req_id;
222 data->userdata = user_data;
224 _get_lang (sys_country, sys_lang);
225 keyword = location_poi_filter_get(filter, "KEYWORD");
227 MOD_LOGW("OSM supports only keyword filter.");
228 return LOCATION_ERROR_PARAMETER;
232 lang = location_map_pref_get_language (svc_pref);
233 // if (!lang) lang = sys_lang;
235 country_code = location_map_pref_get_country(svc_pref);
236 // if (!country_code) country_code = sys_country;
238 max_result = location_poi_pref_get_max_result(pref);
240 LocationPosition *left_top = boundary->rect.left_top;
241 LocationPosition *right_bottom = boundary->rect.right_bottom;
243 left = left_top->latitude;
244 top = left_top->longitude;
245 right = right_bottom->latitude;
246 bottom = right_bottom->longitude;
248 geoclue_poi_search_by_position_async (osm->poi, keyword, lang, country_code, max_result, left, top, right, bottom, _poi_callback, data);
250 return LOCATION_ERROR_NONE;