2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include "mapquest_place.h"
22 #include "mapquest_types.h"
23 #include "mapquest_server_private.h"
24 #include "mapquest_debug.h"
25 #include "mapquest_queue.h"
26 #include "mapquest_restcurl.h"
27 #include "mapquest_util.h"
29 #define PLACES_URL "https://open.mapquestapi.com/nominatim/v1/search.php?format=json"
31 int query_places(gchar *maps_key, gchar *search_str, mapquest_boundary_s *boundary, int num_res, gpointer user_data)
36 strcpy(url, PLACES_URL);
38 if (search_str != NULL) {
39 snprintf(tmpStr, sizeof(tmpStr), "&q=%s", search_str);
40 strncat(url, tmpStr, sizeof(url)-strlen(url)-1);
43 if (boundary != NULL) {
44 if (boundary->type == MAPQUEST_BOUNDARY_RECT) {
45 snprintf(tmpStr, sizeof(tmpStr), "&viewbox=%f,%f,%f,%f", boundary->rect.top_left.longitude, boundary->rect.top_left.latitude, boundary->rect.bottom_right.longitude, boundary->rect.bottom_right.latitude);
47 strncat(url, tmpStr, sizeof(url)-strlen(url)-1);
48 } else if (boundary->type == MAPQUEST_BOUNDARY_CIRCLE) {
49 coords_s *top_left = NULL, *bottom_right = NULL;
50 coords_s circle = boundary->circle.center;
51 gdouble radius = (boundary->circle.radius) * 0.001;
53 /* Calculate the top left coordinate of bounding box. */
54 calculate_point(circle.latitude, circle.longitude, 315, radius, &top_left);
56 /* Calculate the bottom right coordinate of bounding box. */
57 calculate_point(circle.latitude, circle.longitude, 135, radius, &bottom_right);
59 if (top_left && bottom_right) {
60 snprintf(tmpStr, sizeof(tmpStr), "&viewbox=%f,%f,%f,%f", top_left->longitude, top_left->latitude, bottom_right->longitude, bottom_right->latitude);
61 strncat(url, tmpStr, sizeof(url)-strlen(url)-1);
74 strcat(url, "&bounded=1");
77 strcat(url, "&addressdetails=1");
80 snprintf(tmpStr, sizeof(tmpStr), "&limit=%d", num_res);
84 add_handle(url, REQ_TYPE_PLACES, user_data);