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"
27 #define ROUTE_URL "https://open.mapquestapi.com/directions/v2/route?key=%s&ambiguities=ignore&outFormat=json&shapeFormat=raw&generalize=0"
29 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)
35 snprintf(tmpStr, sizeof(tmpStr), ROUTE_URL, maps_key);
37 snprintf(tmpStr, sizeof(tmpStr), ROUTE_URL, "null");
41 strcat(url, "&unit=m"); /* Keeping default as miles and conversion will be done later */
43 if (type == ROUTE_TYPE_FASTEST)
44 strcat(url, "&routeType=fastest");
45 else if (type == ROUTE_TYPE_SHORTEST)
46 strcat(url, "&routeType=shortest");
47 else if (type == ROUTE_TYPE_PEDESTRIAN)
48 strcat(url, "&routeType=pedestrian");
49 else if (type == ROUTE_TYPE_MULTIMODAL)
50 strcat(url, "&routeType=multimodal");
51 else if (type == ROUTE_TYPE_BICYCLE)
52 strcat(url, "&routeType=bicycle");
54 if (avoids == ROUTE_AVOID_LIMITED_ACCESS)
55 strcat(url, "&avoids=Limited Access");
56 else if (avoids == ROUTE_AVOID_TOLL_ROAD)
57 strcat(url, "&avoids=Tollroad");
58 else if (avoids == ROUTE_AVOID_FERRY)
59 strcat(url, "&avoids=Ferry");
60 else if (avoids == ROUTE_AVOID_UNPAVED)
61 strcat(url, "&avoids=Unpaved");
62 else if (avoids == ROUTE_AVOID_SEASONAL_CLOSURE)
63 strcat(url, "&avoids=Approximate Seasonal Closure");
64 else if (avoids == ROUTE_AVOID_COUNTRY_BORDER_CROSSING)
65 strcat(url, "&avoids=Country border crossing");
67 if (style == DRIVING_STYLE_NORMAL)
68 strcat(url, "&drivingStyle=2");
69 else if (style == DRIVING_STYLE_CAUTIOUS)
70 strcat(url, "&drivingStyle=1");
71 else if (style == DRIVING_STYLE_AGGRESSIVE)
72 strcat(url, "&drivingStyle=3");
74 int length = g_list_length(waypoints);
77 GList *waypoints_list = NULL;
78 waypoints_list = g_list_first(waypoints);
80 while (waypoints_list) {
82 coords_s *data = (coords_s *) waypoints_list->data;
86 snprintf(tmpStr, sizeof(tmpStr), "&from=%f,%f", data->latitude, data->longitude);
88 snprintf(tmpStr, sizeof(tmpStr), "&to=%f,%f", data->latitude, data->longitude);
92 waypoints_list = g_list_next(waypoints_list);
96 snprintf(tmpStr, sizeof(tmpStr), "&from=%f,%f", startPoint.latitude, startPoint.longitude);
99 snprintf(tmpStr, sizeof(tmpStr), "&to=%f,%f", endPoint.latitude, endPoint.longitude);
103 add_handle(url, REQ_TYPE_ROUTE, user_data);