Completed a-b routing 52/81852/1
authorDuane Gearhart <duane@mapzen.com>
Thu, 28 Jul 2016 18:43:23 +0000 (14:43 -0400)
committerDuane Gearhart <duane@mapzen.com>
Thu, 28 Jul 2016 20:26:35 +0000 (16:26 -0400)
Added multi-leg routing

Change-Id: I3b9f1bff2fce12b4bbc30fd2b32e50f7ae4c4b7a

src/mapzen/mapzen_jsonparser.cpp
src/mapzen/mapzen_queue.c
src/mapzen/mapzen_route.cpp
src/mapzen/mapzen_server_private.h
src/mapzen/mapzen_types.h
src/mapzen/mapzen_util.c
src/mapzen/mapzen_util.h
src/mapzen_plugin.c

index a65ebb8..db22997 100644 (file)
@@ -41,6 +41,7 @@ extern "C" {
 #define ROUTE_UNIT_CONVERSION_MILE_TO_YD(x)    (1760 * (x))
 
 static route_unit __route_unit = UNIT_KM;
+static route_type __route_type = COSTING_AUTO;
 constexpr double kPolylinePrecision = 1E6;
 constexpr double kInvPolylinePrecision = 1.0 / kPolylinePrecision;
 
@@ -344,23 +345,24 @@ static void __parse_place_response(char *response, int size, GList **placeList)
 
 /********************* ROUTE RESPONSE ***********************/
 
-static void __process_shape(std::vector<coords_s>& decoded_shape, GList *shapePoints)
+static void __process_shape(std::vector<coords_s>& decoded_shape, GList **shapePoints)
 {
        MAP_DEBUG(">>>>> START __process_shape");
-       coords_s *coords = NULL;
 
        for (auto& shape_pt : decoded_shape) {
-               coords = (coords_s *)g_malloc0(sizeof(coords_s));
+               coords_s *coords = (coords_s *)g_malloc0(sizeof(coords_s));
                coords->latitude = shape_pt.latitude;
                coords->longitude = shape_pt.longitude;
-               if (shapePoints == NULL)
-                       shapePoints = g_list_append(shapePoints, (gpointer)coords);
+               if ((*shapePoints) == NULL)
+                       (*shapePoints) = g_list_append((*shapePoints), (gpointer)coords);
                else
-                       shapePoints = g_list_insert_before(shapePoints, NULL, (gpointer)coords);
+                       (*shapePoints) = g_list_insert_before((*shapePoints), NULL, (gpointer)coords);
+//             MAP_DEBUG(">>>>> PROCESS __process_shape: lat,lon=%f,%f", coords->latitude, coords->longitude);
        }
        MAP_DEBUG(">>>>> END __process_shape");
 }
 
+// TODO - bounding box was added to service - therefore, remove method when we read from updated service
 static void __create_bounding_box(std::vector<coords_s>& pts, rectangle_s& bounding_box)
 {
        MAP_DEBUG(">>>>> START __create_bounding_box");
@@ -433,7 +435,7 @@ static void __parse_maneuvers(rapidjson::Value::ConstMemberIterator maneuvers, m
                // Set maneuver type
                type = maneuver->FindMember("type");
                if (type != maneuver->MemberEnd()) {
-                       maneuver_resp->type = type->value.GetInt();
+                       maneuver_resp->type = convert_int_to_mapzen_maneuver_type(type->value.GetInt());
                        MAP_DEBUG(">>>>> PROCESS __parse_maneuvers: type=%d", maneuver_resp->type);
                }
 
@@ -570,8 +572,9 @@ static void __parse_route_response(char *response, int size, int *status, mapzen
     __get_string(trip->value, "language", &(*routeResp)->language);
 
        // Set distance units
-    // TODO just read response units and set value
+    // TODO maybe just read units from response and set value
        (*routeResp)->distance_unit = __route_unit;
+       MAP_DEBUG(">>>>> PROCESS __parse_route_response: distance_unit=%d", (*routeResp)->distance_unit);
 
        // Set trip distance and time
        rapidjson::Value::ConstMemberIterator trip_summary = trip->value.FindMember("summary");
@@ -589,8 +592,8 @@ static void __parse_route_response(char *response, int size, int *status, mapzen
        }
 
        // Type
-       // TODO - set from input
-       (*routeResp)->type = COSTING_AUTO;
+       (*routeResp)->type = __route_type;
+       MAP_DEBUG(">>>>> PROCESS __parse_route_response: route_type=%d", (*routeResp)->type);
 
        // Trip bounding box points
        std::vector<coords_s> trip_bounding_box_candidates;
@@ -647,12 +650,16 @@ static void __parse_route_response(char *response, int size, int *status, mapzen
                MAP_DEBUG(">>>>> PROCESS __parse_route_response: Segment shape point count=%d", decoded_shape.size());
 
                // Append shape for route trip and segment
+               // TODO - optimize/improve
+               // TODO - duplicated points between route trip and segments
+               // TODO - currently no generalization - test application has 500 point limit
                MAP_DEBUG(">>>>> PROCESS __parse_route_response: PRE __process_shape");
-               __process_shape(decoded_shape, (*routeResp)->shapePoints);
-               __process_shape(decoded_shape, segment_resp->shapePoints);
+               __process_shape(decoded_shape, &((*routeResp)->shapePoints));
+               __process_shape(decoded_shape, &(segment_resp->shapePoints));
                MAP_DEBUG(">>>>> PROCESS __parse_route_response: POST __process_shape");
 
                // Set segment bounding box
+               // TODO - update to read from service
                rectangle_s segment_bounding_box;
                __create_bounding_box(decoded_shape, segment_bounding_box);
                segment_resp->bounding_box = segment_bounding_box;
@@ -686,6 +693,7 @@ static void __parse_route_response(char *response, int size, int *status, mapzen
        ///////////////////////////////////////////////////////////////////////////
 
        // Trip Bounding box
+       // TODO - update to read from service
        rectangle_s trip_bounding_box;
        __create_bounding_box(trip_bounding_box_candidates, trip_bounding_box);
        (*routeResp)->bounding_box = trip_bounding_box;
@@ -697,6 +705,7 @@ static void __parse_route_response(char *response, int size, int *status, mapzen
 
 void post_curl_response(char *response, int size, mapzen_resp_type type, void *user_data)
 {
+       MAP_DEBUG(">>>>> START post_curl_response");
        if (!response) return;
 
        if (!user_data) {
@@ -922,8 +931,11 @@ void post_curl_response(char *response, int size, mapzen_resp_type type, void *u
                MAP_DEBUG(">>>>> RESP_TYPE_ROUTE");
                int status = -1;
                MapzenRouteQueryData *queryData = (MapzenRouteQueryData *)user_data;
-               MAP_DEBUG(">>>>> set the following: __route_unit");
+               MAP_DEBUG(">>>>> PROCESS post_curl_response set the following: __route_unit and __route_type");
                __route_unit = queryData->unit;
+               __route_type = queryData->type;
+               MAP_DEBUG(">>>>> PROCESS post_curl_response __route_unit=%d", __route_unit);
+               MAP_DEBUG(">>>>> PROCESS post_curl_response __route_type=%d", __route_type);
 
                MAP_DEBUG(">>>>> PROCESS post_curl_response: prepare MapzenRouteResponseData");
                MapzenRouteResponseData *responseData = (MapzenRouteResponseData *)g_malloc(sizeof(MapzenRouteResponseData));
@@ -937,9 +949,9 @@ void post_curl_response(char *response, int size, mapzen_resp_type type, void *u
                                /* Coords Result GList */
                                mapzen_route_resp_s *routeResponse = NULL;
 
-                               MAP_DEBUG(">>>>> PRE __parse_route_response");
+                               MAP_DEBUG(">>>>> PROCESS post_curl_response: PRE __parse_route_response");
                                __parse_route_response(response, size, &status, &routeResponse);
-                               MAP_DEBUG(">>>>> POST __parse_route_response");
+                               MAP_DEBUG(">>>>> PROCESS post_curl_response: POST __parse_route_response");
 
                                if (routeResponse != NULL) {
                                        MAP_DEBUG(">>>>> PROCESS post_curl_response: (routeResponse != NULL)");
@@ -950,12 +962,12 @@ void post_curl_response(char *response, int size, mapzen_resp_type type, void *u
                                        responseData->routeResponse = routeResponse;
                                } else {
                                        /* REPSONSE PARSING FAILURE */
-                                       MAP_DEBUG(">>>>> post_curl_response: routeResponse is NULL");
+                                       MAP_DEBUG(">>>>> PROCESS post_curl_response: routeResponse is NULL");
                                        responseData->error = __convert_status(status);
                                        responseData->routeResponse = NULL;
                                }
                        } else {
-                               MAP_DEBUG(">>>>> post_curl_response: JSON response is NULL");
+                               MAP_DEBUG(">>>>> PROCESS post_curl_response: JSON response is NULL");
                                responseData->error = __convert_status(status);
                                responseData->routeResponse = NULL;
                        }
@@ -978,6 +990,7 @@ void post_curl_response(char *response, int size, mapzen_resp_type type, void *u
                        break;
                }
        }
+       MAP_DEBUG(">>>>> END post_curl_response");
 }
 
 #ifdef __cplusplus
index c140803..97866fd 100644 (file)
@@ -1400,133 +1400,78 @@ static void __free_route_response(void *ptr)
 
        MapzenRouteResponseData *routeData = (MapzenRouteResponseData *) (ptr);
        if (routeData) {
-               MAP_DEBUG(">>>>> __free_route_response PROCESS: routeData");
                 mapzen_route_resp_s *route_info = routeData->routeResponse;
                if (route_info) {
-                       MAP_DEBUG(">>>>> __free_route_response PROCESS: route_info");
-
                        GList *segment_data = NULL;
-                       MAP_DEBUG(">>>>> __free_route_response PROCESS: PRE segment_data");
                        segment_data = g_list_first(route_info->segments);
                        while (segment_data) {
                                mapzen_route_segment *segment = (mapzen_route_segment *) segment_data->data;
 
                                GList *maneuver_data = NULL;
-                               MAP_DEBUG(">>>>> __free_route_response PROCESS: PRE maneuver_data");
                                maneuver_data = g_list_first(segment->maneuvers);
                                while (maneuver_data) {
-                                       MAP_DEBUG(">>>>> __free_route_response PROCESS: maneuver_data");
                                        mapzen_route_maneuver *maneuver = (mapzen_route_maneuver *) maneuver_data->data;
-
                                        if (maneuver->instruction) {
-                                               MAP_DEBUG(">>>>> __free_route_response PROCESS: instruction");
                                                g_free(maneuver->instruction);
                                                maneuver->instruction = NULL;
                                        }
-
                                        if (maneuver->street_name) {
-                                               MAP_DEBUG(">>>>> __free_route_response PROCESS: street_name");
                                                g_free(maneuver->street_name);
                                                maneuver->street_name = NULL;
                                        }
-
-                                       MAP_DEBUG(">>>>> __free_route_response PROCESS: PRE segments->maneuvers g_list_remove");
                                        segment->maneuvers = g_list_remove(segment->maneuvers, (gpointer)maneuver);
-                                       MAP_DEBUG(">>>>> __free_route_response PROCESS: POST segments->maneuvers g_list_remove");
-
                                        g_free(maneuver);
                                        maneuver = NULL;
-
-                                       MAP_DEBUG(">>>>> __free_route_response PROCESS: PRE segment->maneuvers g_list_first");
                                        /* Fetching the next item from Maneuver/Segment list */
                                        maneuver_data = g_list_first(segment->maneuvers);
-                                       MAP_DEBUG(">>>>> __free_route_response PROCESS: POST segment->maneuvers g_list_first");
                                } /* Loop over maneuvers */
 
-                               MAP_DEBUG(">>>>> __free_route_response PROCESS: POST while (maneuver_data)");
                                g_list_free(segment->maneuvers);
                                segment->maneuvers = NULL;
 
                                GList *segmentShapePoints = NULL;
-                               MAP_DEBUG(">>>>> __free_route_response PROCESS: PRE segmentShapePoints");
                                segmentShapePoints = g_list_first(segment->shapePoints);
                                while (segmentShapePoints) {
-                                       MAP_DEBUG(">>>>> __free_route_response PROCESS: segmentShapePoints");
                                        coords_s *data = (coords_s *) segmentShapePoints->data;
-
-                                       MAP_DEBUG(">>>>> __free_route_response PROCESS: PRE g_list_remove");
                                        segment->shapePoints = g_list_remove(segment->shapePoints, (gpointer)data);
-                                       MAP_DEBUG(">>>>> __free_route_response PROCESS: POST g_list_remove");
-
                                        g_free(data);
                                        data = NULL;
-
-                                       MAP_DEBUG(">>>>> __free_route_response PROCESS: PRE g_list_first");
                                        segmentShapePoints = g_list_first(segment->shapePoints);
-                                       MAP_DEBUG(">>>>> __free_route_response PROCESS: POST g_list_first");
                                }
-
-                               MAP_DEBUG(">>>>> __free_route_response PROCESS: POST while (segmentShapePoints)");
                                g_list_free(segment->shapePoints);
                                segment->shapePoints = NULL;
-
-                               MAP_DEBUG(">>>>> __free_route_response PROCESS: PRE route_info->segments g_list_remove");
                                route_info->segments = g_list_remove(route_info->segments, (gpointer)segment);
-                               MAP_DEBUG(">>>>> __free_route_response PROCESS: POST route_info->segments g_list_remove");
-
                                g_free(segment);
                                segment = NULL;
-
-                               MAP_DEBUG(">>>>> __free_route_response PROCESS: PRE route_info->segments g_list_first");
                                /* Fetching the next item from Maneuver/Segment list */
                                segment_data = g_list_first(route_info->segments);
-                               MAP_DEBUG(">>>>> __free_route_response PROCESS: POST route_info->segments g_list_first");
 
                        } /* Loop over segments */
 
-                       MAP_DEBUG(">>>>> __free_route_response PROCESS: POST while (segment_data)");
                        g_list_free(route_info->segments);
                        route_info->segments = NULL;
 
                        GList *shapePoints = NULL;
-                       MAP_DEBUG(">>>>> __free_route_response PROCESS: PRE shapePoints");
                        shapePoints = g_list_first(route_info->shapePoints);
                        while (shapePoints) {
-                               MAP_DEBUG(">>>>> __free_route_response PROCESS: shapePoints");
                                coords_s *data = (coords_s *) shapePoints->data;
-
-                               MAP_DEBUG(">>>>> __free_route_response PROCESS: PRE g_list_remove");
                                route_info->shapePoints = g_list_remove(route_info->shapePoints, (gpointer)data);
-                               MAP_DEBUG(">>>>> __free_route_response PROCESS: POST g_list_remove");
-
                                g_free(data);
                                data = NULL;
-
-                               MAP_DEBUG(">>>>> __free_route_response PROCESS: PRE g_list_first");
                                shapePoints = g_list_first(route_info->shapePoints);
-                               MAP_DEBUG(">>>>> __free_route_response PROCESS: POST g_list_first");
                        }
-                       MAP_DEBUG(">>>>> __free_route_response PROCESS: POST while (shapePoints)");
                        g_list_free(route_info->shapePoints);
                        route_info->shapePoints = NULL;
-
                        if (route_info->language) {
-                               MAP_DEBUG(">>>>> __free_route_response PROCESS: language");
                                g_free(route_info->language);
                                route_info->language = NULL;
                        }
-
-                       MAP_DEBUG(">>>>> __free_route_response PROCESS: g_free(route_info)");
                        g_free(route_info);
                        route_info = NULL;
                }
-               MAP_DEBUG(">>>>> __free_route_response PROCESS: POST route_info");
-
                if (routeData->user_data) {
-                       MAP_DEBUG(">>>>> __free_route_response PROCESS: user_data");
                        g_free(routeData->user_data);
                        routeData->user_data = NULL;
-                       MAP_DEBUG(">>>>> __free_route_response PROCESS: POST user_data");
                }
        }
        MAP_DEBUG(">>>>> END __free_route_response");
@@ -1798,6 +1743,7 @@ int start_route_service(mapzen_route_req_s *req_details, mapzen_route_cb callbac
                        queryData->origin = req_details->from;
                        queryData->destination = req_details->to;
                        queryData->unit = req_details->unit;
+                       queryData->type = req_details->type;
                        queryData->user_data = user_data;
 
                        query_route(req_details->maps_key, req_details->from, req_details->to, req_details->type, req_details->avoids, req_details->driving_style, req_details->way_points, queryData);
index 41db4f2..361a39f 100644 (file)
@@ -65,7 +65,6 @@ int query_route(gchar *maps_key, coords_s startPoint, coords_s endPoint, route_t
        int length = g_list_length(waypoints);
        if (length != 0) {
                MAP_DEBUG(">>>>> query_route: PROCESS list of route locations");
-               int index = 0;
                GList *waypoints_list = NULL;
                waypoints_list = g_list_first(waypoints);
            writer.Key("locations");
@@ -73,16 +72,13 @@ int query_route(gchar *maps_key, coords_s startPoint, coords_s endPoint, route_t
 
                while (waypoints_list) {
                        coords_s *data = (coords_s *) waypoints_list->data;
-                       for (unsigned i = 0; i < sizeof(data); i++) {
-                               writer.StartObject();
-                               writer.Key("lat");
-                               writer.Double(data[i].latitude);
-                               writer.Key("lon");
-                               writer.Double(data[i].longitude);
-                               writer.EndObject();
-                       }
+                       writer.StartObject();
+                       writer.Key("lat");
+                       writer.Double(data->latitude);
+                       writer.Key("lon");
+                       writer.Double(data->longitude);
+                       writer.EndObject();
                        waypoints_list = g_list_next(waypoints_list);
-                       index++;
                }
            writer.EndArray();
        } else {
index e96c998..072c25d 100644 (file)
@@ -57,6 +57,7 @@ typedef struct {
        coords_s origin;
        coords_s destination;
        route_unit unit;
+       route_type type;
        void *user_data;
 } MapzenRouteQueryData;
 
index 8c70154..6023bf8 100644 (file)
@@ -51,10 +51,51 @@ typedef enum {
 } route_type;
 
 typedef enum {
-       UNIT_KM /* for kilometers */
+       UNIT_KM = 0,    /* for kilometers */
+       UNIT_MI = 1     /* for miles */
 } route_unit;
 
 typedef enum {
+       MAPZEN_MANEUVER_TYPE_NONE = 0,
+       MAPZEN_MANEUVER_TYPE_START = 1,
+       MAPZEN_MANEUVER_TYPE_START_RIGHT = 2,
+       MAPZEN_MANEUVER_TYPE_START_LEFT = 3,
+       MAPZEN_MANEUVER_TYPE_DESTINATION = 4,
+       MAPZEN_MANEUVER_TYPE_DESTINATION_RIGHT = 5,
+       MAPZEN_MANEUVER_TYPE_DESTINATION_LEFT = 6,
+       MAPZEN_MANEUVER_TYPE_BECOMES = 7,
+       MAPZEN_MANEUVER_TYPE_CONTINUE = 8,
+       MAPZEN_MANEUVER_TYPE_SLIGHT_RIGHT = 9,
+       MAPZEN_MANEUVER_TYPE_RIGHT = 10,
+       MAPZEN_MANEUVER_TYPE_SHARP_RIGHT = 11,
+       MAPZEN_MANEUVER_TYPE_UTURN_RIGHT = 12,
+       MAPZEN_MANEUVER_TYPE_UTURN_LEFT = 13,
+       MAPZEN_MANEUVER_TYPE_SHARP_LEFT = 14,
+       MAPZEN_MANEUVER_TYPE_LEFT = 15,
+       MAPZEN_MANEUVER_TYPE_SLIGHT_LEFT = 16,
+       MAPZEN_MANEUVER_TYPE_RAMP_STRAIGHT = 17,
+       MAPZEN_MANEUVER_TYPE_RAMP_RIGHT = 18,
+       MAPZEN_MANEUVER_TYPE_RAMP_LEFT = 19,
+       MAPZEN_MANEUVER_TYPE_EXIT_RIGHT = 20,
+       MAPZEN_MANEUVER_TYPE_EXIT_LEFT = 21,
+       MAPZEN_MANEUVER_TYPE_STAY_STRAIGHT = 22,
+       MAPZEN_MANEUVER_TYPE_STAY_RIGHT = 23,
+       MAPZEN_MANEUVER_TYPE_STAY_LEFT = 24,
+       MAPZEN_MANEUVER_TYPE_MERGE = 25,
+       MAPZEN_MANEUVER_TYPE_ROUNDABOUT_ENTER = 26,
+       MAPZEN_MANEUVER_TYPE_ROUNDABOUT_EXIT = 27,
+       MAPZEN_MANEUVER_TYPE_FERRY_ENTER = 28,
+       MAPZEN_MANEUVER_TYPE_FERRY_EXIT = 29,
+       MAPZEN_MANEUVER_TYPE_TRANSIT = 30,
+       MAPZEN_MANEUVER_TYPE_TRANSIT_TRANSFER = 31,
+       MAPZEN_MANEUVER_TYPE_TRANSIT_REMAIN_ON = 32,
+       MAPZEN_MANEUVER_TYPE_TRANSIT_CONNECTION_START = 33,
+       MAPZEN_MANEUVER_TYPE_TRANSIT_CONNECTION_TRANSFER = 34,
+       MAPZEN_MANEUVER_TYPE_TRANSIT_CONNECTION_DESTINATION = 35,
+       MAPZEN_MANEUVER_TYPE_POST_TRANSIT_CONNECTION_DESTINATION = 36
+} mapzen_maneuver_type;
+
+typedef enum {
        PENALTY_NONE = 0, //TODO: Mapzen does not have currently
        PENALTY_LIMITED_ACCESS, //TODO: Mapzen does not have currently
        PENALTY_TOLL_ROADS, //set to > 0 to avoid
@@ -176,7 +217,7 @@ typedef struct {
        coords_s end_point;
        gdouble distance;
        guint time;
-       guint type;
+       mapzen_maneuver_type type;
        gchar *instruction;
        gchar *street_name;
 } mapzen_route_maneuver;
index 012d770..3df9bc9 100644 (file)
@@ -18,6 +18,7 @@
 #include "mapzen_debug.h"
 #include <maps_error.h>
 #include <maps_view.h>
+#include <maps_route_maneuver.h>
 #include <math.h>
 
 #define PI 3.14159265359
@@ -109,6 +110,94 @@ int convert_mapzen_error_to_maps_error(int error)
        }
 }
 
+mapzen_maneuver_type convert_int_to_mapzen_maneuver_type(int maneuver_type_id)
+{
+       switch (maneuver_type_id) {
+       case 0:  return MAPZEN_MANEUVER_TYPE_NONE;
+       case 1:  return MAPZEN_MANEUVER_TYPE_START;
+       case 2:  return MAPZEN_MANEUVER_TYPE_START_RIGHT;
+       case 3:  return MAPZEN_MANEUVER_TYPE_START_LEFT;
+       case 4:  return MAPZEN_MANEUVER_TYPE_DESTINATION;
+       case 5:  return MAPZEN_MANEUVER_TYPE_DESTINATION_RIGHT;
+       case 6:  return MAPZEN_MANEUVER_TYPE_DESTINATION_LEFT;
+       case 7:  return MAPZEN_MANEUVER_TYPE_BECOMES;
+       case 8:  return MAPZEN_MANEUVER_TYPE_CONTINUE;
+       case 9:  return MAPZEN_MANEUVER_TYPE_SLIGHT_RIGHT;
+       case 10: return MAPZEN_MANEUVER_TYPE_RIGHT;
+       case 11: return MAPZEN_MANEUVER_TYPE_SHARP_RIGHT;
+       case 12: return MAPZEN_MANEUVER_TYPE_UTURN_RIGHT;
+       case 13: return MAPZEN_MANEUVER_TYPE_UTURN_LEFT;
+       case 14: return MAPZEN_MANEUVER_TYPE_SHARP_LEFT;
+       case 15: return MAPZEN_MANEUVER_TYPE_LEFT;
+       case 16: return MAPZEN_MANEUVER_TYPE_SLIGHT_LEFT;
+       case 17: return MAPZEN_MANEUVER_TYPE_RAMP_STRAIGHT;
+       case 18: return MAPZEN_MANEUVER_TYPE_RAMP_RIGHT;
+       case 19: return MAPZEN_MANEUVER_TYPE_RAMP_LEFT;
+       case 20: return MAPZEN_MANEUVER_TYPE_EXIT_RIGHT;
+       case 21: return MAPZEN_MANEUVER_TYPE_EXIT_LEFT;
+       case 22: return MAPZEN_MANEUVER_TYPE_STAY_STRAIGHT;
+       case 23: return MAPZEN_MANEUVER_TYPE_STAY_RIGHT;
+       case 24: return MAPZEN_MANEUVER_TYPE_STAY_LEFT;
+       case 25: return MAPZEN_MANEUVER_TYPE_MERGE;
+       case 26: return MAPZEN_MANEUVER_TYPE_ROUNDABOUT_ENTER;
+       case 27: return MAPZEN_MANEUVER_TYPE_ROUNDABOUT_EXIT;
+       case 28: return MAPZEN_MANEUVER_TYPE_FERRY_ENTER;
+       case 29: return MAPZEN_MANEUVER_TYPE_FERRY_EXIT;
+       case 30: return MAPZEN_MANEUVER_TYPE_TRANSIT;
+       case 31: return MAPZEN_MANEUVER_TYPE_TRANSIT_TRANSFER;
+       case 32: return MAPZEN_MANEUVER_TYPE_TRANSIT_REMAIN_ON;
+       case 33: return MAPZEN_MANEUVER_TYPE_TRANSIT_CONNECTION_START;
+       case 34: return MAPZEN_MANEUVER_TYPE_TRANSIT_CONNECTION_TRANSFER;
+       case 35: return MAPZEN_MANEUVER_TYPE_TRANSIT_CONNECTION_DESTINATION;
+       case 36: return MAPZEN_MANEUVER_TYPE_POST_TRANSIT_CONNECTION_DESTINATION;
+       default: return MAPZEN_MANEUVER_TYPE_NONE;
+       }
+}
+
+int convert_mapzen_maneuver_type_to_maps_turn_type(mapzen_maneuver_type maneuver_type)
+{
+       switch (maneuver_type) {
+       case MAPZEN_MANEUVER_TYPE_NONE:  return MAPS_ROUTE_TURN_TYPE_NONE;
+       case MAPZEN_MANEUVER_TYPE_START:  return MAPS_ROUTE_TURN_TYPE_STRAIGHT;
+       case MAPZEN_MANEUVER_TYPE_START_RIGHT:  return MAPS_ROUTE_TURN_TYPE_STRAIGHT;
+       case MAPZEN_MANEUVER_TYPE_START_LEFT:  return MAPS_ROUTE_TURN_TYPE_STRAIGHT;
+       case MAPZEN_MANEUVER_TYPE_DESTINATION:  return MAPS_ROUTE_TURN_TYPE_NONE;
+       case MAPZEN_MANEUVER_TYPE_DESTINATION_RIGHT:  return MAPS_ROUTE_TURN_TYPE_NONE;
+       case MAPZEN_MANEUVER_TYPE_DESTINATION_LEFT:  return MAPS_ROUTE_TURN_TYPE_NONE;
+       case MAPZEN_MANEUVER_TYPE_BECOMES:  return MAPS_ROUTE_TURN_TYPE_STRAIGHT;
+       case MAPZEN_MANEUVER_TYPE_CONTINUE:  return MAPS_ROUTE_TURN_TYPE_STRAIGHT;
+       case MAPZEN_MANEUVER_TYPE_SLIGHT_RIGHT:  return MAPS_ROUTE_TURN_TYPE_LIGHT_RIGHT;
+       case MAPZEN_MANEUVER_TYPE_RIGHT:  return MAPS_ROUTE_TURN_TYPE_RIGHT;
+       case MAPZEN_MANEUVER_TYPE_SHARP_RIGHT:  return MAPS_ROUTE_TURN_TYPE_HARD_RIGHT;
+       case MAPZEN_MANEUVER_TYPE_UTURN_RIGHT:  return MAPS_ROUTE_TURN_TYPE_UTURN_RIGHT;
+       case MAPZEN_MANEUVER_TYPE_UTURN_LEFT:  return MAPS_ROUTE_TURN_TYPE_UTURN_LEFT;
+       case MAPZEN_MANEUVER_TYPE_SHARP_LEFT:  return MAPS_ROUTE_TURN_TYPE_HARD_LEFT;
+       case MAPZEN_MANEUVER_TYPE_LEFT:  return MAPS_ROUTE_TURN_TYPE_LEFT;
+       case MAPZEN_MANEUVER_TYPE_SLIGHT_LEFT:  return MAPS_ROUTE_TURN_TYPE_LIGHT_LEFT;
+       case MAPZEN_MANEUVER_TYPE_RAMP_STRAIGHT:  return MAPS_ROUTE_TURN_TYPE_STRAIGHT;
+       case MAPZEN_MANEUVER_TYPE_RAMP_RIGHT:  return MAPS_ROUTE_TURN_TYPE_BEAR_RIGHT;
+       case MAPZEN_MANEUVER_TYPE_RAMP_LEFT:  return MAPS_ROUTE_TURN_TYPE_BEAR_LEFT;
+       case MAPZEN_MANEUVER_TYPE_EXIT_RIGHT:  return MAPS_ROUTE_TURN_TYPE_BEAR_RIGHT;
+       case MAPZEN_MANEUVER_TYPE_EXIT_LEFT:  return MAPS_ROUTE_TURN_TYPE_BEAR_LEFT;
+       case MAPZEN_MANEUVER_TYPE_STAY_STRAIGHT:  return MAPS_ROUTE_TURN_TYPE_STRAIGHT;
+       case MAPZEN_MANEUVER_TYPE_STAY_RIGHT:  return MAPS_ROUTE_TURN_TYPE_BEAR_RIGHT;
+       case MAPZEN_MANEUVER_TYPE_STAY_LEFT:  return MAPS_ROUTE_TURN_TYPE_BEAR_LEFT;
+       case MAPZEN_MANEUVER_TYPE_MERGE:  return MAPS_ROUTE_TURN_TYPE_STRAIGHT;
+       case MAPZEN_MANEUVER_TYPE_ROUNDABOUT_ENTER:  return MAPS_ROUTE_TURN_TYPE_STRAIGHT;
+       case MAPZEN_MANEUVER_TYPE_ROUNDABOUT_EXIT:  return MAPS_ROUTE_TURN_TYPE_STRAIGHT;
+       case MAPZEN_MANEUVER_TYPE_FERRY_ENTER:  return MAPS_ROUTE_TURN_TYPE_STRAIGHT;
+       case MAPZEN_MANEUVER_TYPE_FERRY_EXIT:  return MAPS_ROUTE_TURN_TYPE_STRAIGHT;
+       case MAPZEN_MANEUVER_TYPE_TRANSIT:  return MAPS_ROUTE_TURN_TYPE_NONE;
+       case MAPZEN_MANEUVER_TYPE_TRANSIT_TRANSFER:  return MAPS_ROUTE_TURN_TYPE_NONE;
+       case MAPZEN_MANEUVER_TYPE_TRANSIT_REMAIN_ON:  return MAPS_ROUTE_TURN_TYPE_NONE;
+       case MAPZEN_MANEUVER_TYPE_TRANSIT_CONNECTION_START:  return MAPS_ROUTE_TURN_TYPE_NONE;
+       case MAPZEN_MANEUVER_TYPE_TRANSIT_CONNECTION_TRANSFER:  return MAPS_ROUTE_TURN_TYPE_NONE;
+       case MAPZEN_MANEUVER_TYPE_TRANSIT_CONNECTION_DESTINATION:  return MAPS_ROUTE_TURN_TYPE_NONE;
+       case MAPZEN_MANEUVER_TYPE_POST_TRANSIT_CONNECTION_DESTINATION: return MAPS_ROUTE_TURN_TYPE_NONE;
+       default: return MAPS_ROUTE_TURN_TYPE_NONE;
+       }
+}
+
 int convert_tangram_view_type_to_maps_view_type(int maps_view_type)
 {
        switch (maps_view_type) {
index 07784d4..b05bfef 100644 (file)
@@ -35,6 +35,9 @@ double radians_to_degrees(double radians);
 
 int convert_maps_error_to_mapzen_error(int error);
 int convert_mapzen_error_to_maps_error(int error);
+mapzen_maneuver_type convert_int_to_mapzen_maneuver_type(int maneuver_type_id);
+int convert_mapzen_maneuver_type_to_maps_turn_type(mapzen_maneuver_type maneuver_type);
+
 int convert_tangram_view_type_to_maps_view_type(int maps_view_type);
 int convert_maps_view_type_to_tangram_view_type(int maps_view_type);
 
index fac363b..eebec7f 100644 (file)
@@ -43,41 +43,6 @@ static maps_item_hashtable_h preference_plugin = NULL;
 
 int __maps_service_instance_count = 0;
 
-/*
-static maps_route_turn_type_e __convert_route_turn_type(int index)
-{
-       maps_route_turn_type_e type = MAPS_ROUTE_TURN_TYPE_NONE;
-
-       if (index == 0)
-               type = MAPS_ROUTE_TURN_TYPE_STRAIGHT;
-       else if (index == 1)
-               type = MAPS_ROUTE_TURN_TYPE_LIGHT_RIGHT;
-       else if (index == 2)
-               type = MAPS_ROUTE_TURN_TYPE_RIGHT;
-       else if (index == 3)
-               type = MAPS_ROUTE_TURN_TYPE_HARD_RIGHT;
-       else if (index == 5)
-               type = MAPS_ROUTE_TURN_TYPE_HARD_LEFT;
-       else if (index == 6)
-               type = MAPS_ROUTE_TURN_TYPE_LIGHT_LEFT;
-       else if (index == 7)
-               type = MAPS_ROUTE_TURN_TYPE_LIGHT_LEFT;
-       else if (index == 8)
-               type = MAPS_ROUTE_TURN_TYPE_UTURN_RIGHT;
-       else if (index == 9)
-               type = MAPS_ROUTE_TURN_TYPE_UTURN_LEFT;
-       else if (index == 16)
-               type = MAPS_ROUTE_TURN_TYPE_RIGHT_FORK;
-       else if (index == 17)
-               type = MAPS_ROUTE_TURN_TYPE_LEFT_FORK;
-       else if (index == 18)
-               type = MAPS_ROUTE_TURN_TYPE_STRAIGHT_FORK;
-       else
-               type = MAPS_ROUTE_TURN_TYPE_NONE;
-
-       return type;
-}*/
-
 EXPORT_API int maps_plugin_multi_reverse_geocode(const maps_coordinates_list_h geocode_list,
        const maps_preference_h preference, maps_service_multi_reverse_geocode_cb callback,
        void *user_data, int *request_id)
@@ -675,17 +640,21 @@ static void __mapzen_route_cb(mapzen_error_e result, int request_id, mapzen_rout
                switch (route_info->type) {
                case COSTING_BICYCLE:
                        maps_route_set_transport_mode(tizen_route, MAPS_ROUTE_TRANSPORT_MODE_BICYCLE);
+                       MAPS_LOGD(">>>>> __mapzen_route_cb: PROCESS route_info->type=COSTING_BICYCLE");
                        break;
                case COSTING_MULTIMODAL:
                        maps_route_set_transport_mode(tizen_route, MAPS_ROUTE_TRANSPORT_MODE_PUBLICTRANSIT);
+                       MAPS_LOGD(">>>>> __mapzen_route_cb: PROCESS route_info->type=COSTING_MULTIMODAL");
                        break;
                case COSTING_PEDESTRIAN:
                        maps_route_set_transport_mode(tizen_route, MAPS_ROUTE_TRANSPORT_MODE_PEDESTRIAN);
+                       MAPS_LOGD(">>>>> __mapzen_route_cb: PROCESS route_info->type=COSTING_PEDESTRIAN");
                        break;
                case COSTING_AUTO:
                case COSTING_AUTO_SHORTER:
                default:
                        maps_route_set_transport_mode(tizen_route, MAPS_ROUTE_TRANSPORT_MODE_CAR);
+                       MAPS_LOGD(">>>>> __mapzen_route_cb: PROCESS route_info->type=COSTING_AUTO");
                        break;
                }
 
@@ -769,7 +738,22 @@ static void __mapzen_route_cb(mapzen_error_e result, int request_id, mapzen_rout
                        maps_route_segment_set_duration(tizen_segment, segment->time);
 
                        /* Set segment path */
-                       /* TODO */
+                       GList *segment_points = NULL;
+                       segment_points = g_list_first(segment->shapePoints);
+                       maps_item_list_h tizen_segment_path_list = NULL;
+                       maps_item_list_create(&tizen_segment_path_list);
+                       MAPS_LOGD(">>>>> __mapzen_route_cb: PROCESS segment_points");
+                       while (segment_points) {
+                               coords_s *data = (coords_s *) segment_points->data;
+                               maps_coordinates_h shapeCoords;
+                               maps_coordinates_create(data->latitude, data->longitude, &shapeCoords);
+                               /* MAPS_LOGD(">>>>> __mapzen_route_cb: PROCESS segment shape=%f,%f", data->latitude, data->longitude); */
+                               maps_item_list_append(tizen_segment_path_list, (gpointer) shapeCoords, maps_coordinates_clone);
+                               maps_coordinates_destroy(shapeCoords);
+                               segment_points = g_list_next(segment_points);
+                       }
+                       maps_route_segment_set_path(tizen_segment, tizen_segment_path_list);
+                       maps_item_list_destroy(tizen_segment_path_list);
 
                        /* Set up for maneuver list */
                        GList *maneuver_data = NULL;
@@ -788,12 +772,11 @@ static void __mapzen_route_cb(mapzen_error_e result, int request_id, mapzen_rout
                                mapzen_route_maneuver *maneuver = (mapzen_route_maneuver *) maneuver_data->data;
 
                                /* Set maneuver direction */
-                               /* TODO just set to none */
+                               maps_route_maneuver_set_direction_id(tizen_maneuver, MAPS_ROUTE_DIRECTION_NONE);
 
                                /* Set turn type from maneuver type */
-                               /* TODO transform */
                                MAPS_LOGD(">>>>> __mapzen_route_cb: PROCESS assign turn type");
-                               /* maps_route_maneuver_set_turn_type(tizen_maneuver, __convert_route_turn_type(maneuver->turn_type)); */
+                               maps_route_maneuver_set_turn_type(tizen_maneuver, convert_mapzen_maneuver_type_to_maps_turn_type(maneuver->type));
 
                                /* Set maneuver position */
                                MAPS_LOGD(">>>>> __mapzen_route_cb: PROCESS assign maneuver position");
@@ -817,7 +800,10 @@ static void __mapzen_route_cb(mapzen_error_e result, int request_id, mapzen_rout
                                }
 
                                /* Set maneuver locale */
-                               /* TODO */
+                               if (route_info->language) {
+                                       MAPS_LOGD(">>>>> __mapzen_route_cb: PROCESS assign locale: %s", route_info->language);
+                                       maps_route_maneuver_set_locale(tizen_maneuver, (char *) route_info->language);
+                               }
 
                                /* Set maneuver distance and time */
                                MAPS_LOGD(">>>>> __mapzen_route_cb: PROCESS assign maneuver distance and time");
@@ -843,8 +829,8 @@ static void __mapzen_route_cb(mapzen_error_e result, int request_id, mapzen_rout
                        maps_item_list_append(tizen_segment_list, (gpointer) tizen_segment, maps_route_segment_clone);
                        maps_route_segment_destroy(tizen_segment);
 
-                       /* Fetching the next item from Segment list */
-                       MAPS_LOGD(">>>>> __mapzen_route_cb: PROCESS Fetching the next item from Segment list");
+                       /* Fetching the next item from segment list */
+                       MAPS_LOGD(">>>>> __mapzen_route_cb: PROCESS Fetching the next item from segment list");
                        segment_data = g_list_next(segment_data);
 
                } /* Loop over segments */
@@ -854,37 +840,25 @@ static void __mapzen_route_cb(mapzen_error_e result, int request_id, mapzen_rout
                maps_route_set_segments(tizen_route, tizen_segment_list);
                maps_item_list_destroy(tizen_segment_list);
 
-               /* Set up for trip shape points/path */
+               /* Set trip path */
+               GList *trip_points = NULL;
+               trip_points = g_list_first(route_info->shapePoints);
                maps_item_list_h tizen_route_path_list = NULL;
                maps_item_list_create(&tizen_route_path_list);
-               GList *shapePoints = NULL;
-               shapePoints = g_list_first(route_info->shapePoints);
-
-               MAPS_LOGD(">>>>> __mapzen_route_cb: PROCESS trip shapePoints");
-               while (shapePoints) {
-                       coords_s *data = (coords_s *) shapePoints->data;
-
+               MAPS_LOGD(">>>>> __mapzen_route_cb: PROCESS trip_points");
+               while (trip_points) {
+                       coords_s *data = (coords_s *) trip_points->data;
                        maps_coordinates_h shapeCoords;
                        maps_coordinates_create(data->latitude, data->longitude, &shapeCoords);
-                       MAPS_LOGD(">>>>> __mapzen_route_cb: PROCESS data->latitude: %f", data->latitude);
-                       MAPS_LOGD(">>>>> __mapzen_route_cb: PROCESS data->longitude: %f", data->longitude);
-
+                       /* MAPS_LOGD(">>>>> __mapzen_route_cb: PROCESS trip shape=%f,%f", data->latitude, data->longitude); */
                        maps_item_list_append(tizen_route_path_list, (gpointer) shapeCoords, maps_coordinates_clone);
-
                        maps_coordinates_destroy(shapeCoords);
-
-                       shapePoints = g_list_next(shapePoints);
+                       trip_points = g_list_next(trip_points);
                }
-
-               /* Set trip path */
                maps_route_set_path(tizen_route, tizen_route_path_list);
                maps_item_list_destroy(tizen_route_path_list);
-               MAPS_LOGD(">>>>> __mapzen_route_cb: PROCESS shapePoints DONE");
 
-               MAPS_LOGD(">>>>> PROCESS __mapzen_route_cb: result=%d", result);
-               MAPS_LOGD(">>>>> PROCESS __mapzen_route_cb: convert_mapzen_error_to_maps_error(result)=%d", convert_mapzen_error_to_maps_error(result));
                MAPS_LOGD(">>>>> PRE calldata_route->callback");
-               MAPS_LOGD(">>>>> PRE calldata_route->callback address: %p", calldata_route->callback);
                bool b = calldata_route->callback((maps_error_e)convert_mapzen_error_to_maps_error(result), calldata_route->reqID, 0, 1, tizen_route, calldata_route->data);
                MAPS_LOGD(">>>>> POST calldata_route->callback");
                if (!b)
@@ -901,9 +875,7 @@ static void __mapzen_route_cb(mapzen_error_e result, int request_id, mapzen_rout
 EXPORT_API int maps_plugin_search_route(const maps_coordinates_h origin,
                const maps_coordinates_h destination, maps_preference_h preference,
                maps_service_search_route_cb callback, void *user_data, int *request_id) {
-       MAPS_LOGD(">>>>> START maps_plugin_search_route");
-       MAPS_LOGD(">>>>> maps_plugin_search_route PROCESS: callback address=%p", callback);
-       MAPS_LOGD(">>>>> maps_plugin_search_route PROCESS: request_id=%d", *request_id);
+       MAPS_LOGD(">>>>> START maps_plugin_search_route: request_id=%d", *request_id);
 
        if (!origin || !destination || !callback || !request_id)
                return MAPS_ERROR_INVALID_PARAMETER;
@@ -958,7 +930,6 @@ EXPORT_API int maps_plugin_search_route(const maps_coordinates_h origin,
                break;
        default:
                return MAPS_ERROR_INVALID_PARAMETER;
-               break;
        }
 
        /* Unit */
@@ -997,7 +968,6 @@ EXPORT_API int maps_plugin_search_route(const maps_coordinates_h origin,
                        break;
                default:
                        return MAPS_ERROR_INVALID_PARAMETER;
-                       break;
                }
        }
 
@@ -1005,18 +975,21 @@ EXPORT_API int maps_plugin_search_route(const maps_coordinates_h origin,
 
        *request_id = ++__request_id;
        calldata_route->reqID = __request_id;
-       MAPS_LOGD(">>>>> maps_plugin_search_route PROCESS: calldata_route->reqID=%d", calldata_route->reqID);
+       MAPS_LOGD(">>>>> PROCESS maps_plugin_search_route: calldata_route->reqID=%d", calldata_route->reqID);
 
-       MAPS_LOGD(">>>>> PRE mapzen_start_route");
+       MAPS_LOGD(">>>>> PROCESS maps_plugin_search_route: PRE mapzen_start_route");
        int ret = mapzen_start_route(route_req, __mapzen_route_cb, __request_id, (void *)calldata_route);
-       MAPS_LOGD(">>>>> POST mapzen_start_route");
+       MAPS_LOGD(">>>>> PROCESS maps_plugin_search_route: POST mapzen_start_route");
 
        MAPS_LOGD(">>>>> END maps_plugin_search_route");
        return convert_mapzen_error_to_maps_error(ret);
 }
 
-EXPORT_API int maps_plugin_search_route_waypoints(const maps_coordinates_h *waypoint_list, int waypoint_num, maps_preference_h preference, maps_service_search_route_cb callback, void *user_data, int *request_id)
-{
+EXPORT_API int maps_plugin_search_route_waypoints(
+               const maps_coordinates_h *waypoint_list, int waypoint_num,
+               maps_preference_h preference, maps_service_search_route_cb callback,
+               void *user_data, int *request_id) {
+       MAPS_LOGD(">>>>> START maps_plugin_search_route_waypoints");
        if (!waypoint_list || waypoint_num < 2 || !callback || !request_id)
                return MAPS_ERROR_INVALID_PARAMETER;
 
@@ -1100,7 +1073,6 @@ EXPORT_API int maps_plugin_search_route_waypoints(const maps_coordinates_h *wayp
                        break;
                default:
                        return MAPS_ERROR_INVALID_PARAMETER;
-                       break;
                }
        }
 
@@ -1119,6 +1091,7 @@ EXPORT_API int maps_plugin_search_route_waypoints(const maps_coordinates_h *wayp
                                        data->latitude = latitude;
                                        data->longitude = longitude;
 
+                                       MAPS_LOGD(">>>>> PROCESS maps_plugin_search_route_waypoints: ll[%d]=%f,%f", index, data->latitude, data->longitude);
                                        if (route_req->way_points == NULL)
                                                route_req->way_points = g_list_append(route_req->way_points, (gpointer) data);
                                        else
@@ -1131,8 +1104,11 @@ EXPORT_API int maps_plugin_search_route_waypoints(const maps_coordinates_h *wayp
        *request_id = ++__request_id;
        calldata_route->reqID = __request_id;
 
+       MAPS_LOGD(">>>>> PROCESS maps_plugin_search_route_waypoints: PRE mapzen_start_route");
        int ret = mapzen_start_route(route_req, __mapzen_route_cb, __request_id, (void *)calldata_route);
+       MAPS_LOGD(">>>>> PROCESS maps_plugin_search_route_waypoints: POST mapzen_start_route");
 
+       MAPS_LOGD(">>>>> END maps_plugin_search_route_waypoints");
        return convert_mapzen_error_to_maps_error(ret);
 }