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.
20 #include "mapquest_route.h"
21 #include "mapquest_types.h"
22 #include "mapquest_server_private.h"
23 #include "mapquest_debug.h"
24 #include "mapquest_queue.h"
25 #include "mapquest_restcurl.h"
26 #include "mapquest_util.h"
28 #define ROUTE_URL "https://open.mapquestapi.com/directions/v2/route?key=%s&ambiguities=ignore&outFormat=json&shapeFormat=raw&generalize=0"
30 int query_route(gchar *maps_key, coords_s startPoint, coords_s endPoint, route_type type, route_feature_avoids avoids, route_driving_style style, GList *waypoints, gpointer user_data)
36 snprintf(tmpStr, sizeof(tmpStr), ROUTE_URL, maps_key);
38 snprintf(tmpStr, sizeof(tmpStr), ROUTE_URL, "null");
42 STRCAT(url, "&unit=m"); /* Keeping default as miles and conversion will be done later */
44 if (type == ROUTE_TYPE_FASTEST)
45 STRCAT(url, "&routeType=fastest");
46 else if (type == ROUTE_TYPE_SHORTEST)
47 STRCAT(url, "&routeType=shortest");
48 else if (type == ROUTE_TYPE_PEDESTRIAN)
49 STRCAT(url, "&routeType=pedestrian");
50 else if (type == ROUTE_TYPE_MULTIMODAL)
51 STRCAT(url, "&routeType=multimodal");
52 else if (type == ROUTE_TYPE_BICYCLE)
53 STRCAT(url, "&routeType=bicycle");
55 if (avoids == ROUTE_AVOID_LIMITED_ACCESS)
56 STRCAT(url, "&avoids=Limited Access");
57 else if (avoids == ROUTE_AVOID_TOLL_ROAD)
58 STRCAT(url, "&avoids=Tollroad");
59 else if (avoids == ROUTE_AVOID_FERRY)
60 STRCAT(url, "&avoids=Ferry");
61 else if (avoids == ROUTE_AVOID_UNPAVED)
62 STRCAT(url, "&avoids=Unpaved");
63 else if (avoids == ROUTE_AVOID_SEASONAL_CLOSURE)
64 STRCAT(url, "&avoids=Approximate Seasonal Closure");
65 else if (avoids == ROUTE_AVOID_COUNTRY_BORDER_CROSSING)
66 STRCAT(url, "&avoids=Country border crossing");
68 if (style == DRIVING_STYLE_NORMAL)
69 STRCAT(url, "&drivingStyle=2");
70 else if (style == DRIVING_STYLE_CAUTIOUS)
71 STRCAT(url, "&drivingStyle=1");
72 else if (style == DRIVING_STYLE_AGGRESSIVE)
73 STRCAT(url, "&drivingStyle=3");
75 int length = g_list_length(waypoints);
78 GList *waypoints_list = NULL;
79 waypoints_list = g_list_first(waypoints);
81 while (waypoints_list) {
83 coords_s *data = (coords_s *) waypoints_list->data;
87 snprintf(tmpStr, sizeof(tmpStr), "&from=%f,%f", data->latitude, data->longitude);
89 snprintf(tmpStr, sizeof(tmpStr), "&to=%f,%f", data->latitude, data->longitude);
93 waypoints_list = g_list_next(waypoints_list);
97 snprintf(tmpStr, sizeof(tmpStr), "&from=%f,%f", startPoint.latitude, startPoint.longitude);
100 snprintf(tmpStr, sizeof(tmpStr), "&to=%f,%f", endPoint.latitude, endPoint.longitude);
104 add_handle(url, REQ_TYPE_ROUTE, user_data);