2 #include "maps_test_search_route.h"
3 #include "maps_test_log.h"
4 #include "maps_test_util.h"
7 static maps_distance_unit_e g_distance_unit = MAPS_DISTANCE_UNIT_M;
13 static void cleanup(bool result)
22 static bool __maps_route_segment_maneuver_cb(int index, int total, maps_route_maneuver_h maneuver, void *user_data)
24 if (!maneuver) return false;
27 LOG_START("%smaneuver [%d/%d] = {", LOG_PREFIX, index+1, total);
29 if (maps_route_maneuver_get_instruction_text(maneuver, &lv.strval) == MAPS_ERROR_NONE)
30 LOG_PRINT("%s%sinstruction = %s", LOG_PREFIX, LOG_PREFIX, lv.strval);
32 if (maps_route_maneuver_get_distance_to_next_instruction(maneuver, &lv.dblval) == MAPS_ERROR_NONE)
33 LOG_PRINT("%s%sdistance = %.2f %s", LOG_PREFIX, LOG_PREFIX, lv.dblval, get_distance_unit_string(g_distance_unit));
35 if (maps_route_maneuver_get_time_to_next_instruction(maneuver, &lv.intval) == MAPS_ERROR_NONE)
36 LOG_PRINT("%s%stime = %d sec", LOG_PREFIX, LOG_PREFIX, lv.intval);
38 if (maps_route_maneuver_get_direction_id(maneuver, (maps_route_direction_e*)&lv.intval) == MAPS_ERROR_NONE)
39 LOG_PRINT("%s%sdirection_id = %s (%d)", LOG_PREFIX, LOG_PREFIX, get_direction_string(lv.intval), lv.intval);
41 if (maps_route_maneuver_get_turn_type(maneuver, (maps_route_turn_type_e*)&lv.intval) == MAPS_ERROR_NONE)
42 LOG_PRINT("%s%sturn_type = %s (%d)", LOG_PREFIX, LOG_PREFIX, get_turn_type_string(lv.intval), lv.intval);
44 maps_coordinates_h coord;
45 if (maps_route_maneuver_get_position(maneuver, &coord) == MAPS_ERROR_NONE) {
47 maps_coordinates_get_latitude(coord, &lat);
48 maps_coordinates_get_longitude(coord, &lng);
49 LOG_PRINT("%s%sposition = %f, %f", LOG_PREFIX, LOG_PREFIX, lat, lng);
50 maps_coordinates_destroy(coord);
53 if (maps_route_maneuver_get_road_name(maneuver, &lv.strval) == MAPS_ERROR_NONE)
54 LOG_PRINT("%s%sroad_name = %s", LOG_PREFIX, LOG_PREFIX, lv.strval);
56 if (maps_route_maneuver_get_locale(maneuver, &lv.strval) == MAPS_ERROR_NONE)
57 LOG_PRINT("%s%slocale = %s", LOG_PREFIX, LOG_PREFIX, lv.strval);
59 maps_route_maneuver_destroy(maneuver);
61 LOG_FINISH("%s}", LOG_PREFIX);
66 static bool __maps_route_path_cb(int index, int total, maps_coordinates_h coordinates, void *user_data)
68 if (!coordinates) return false;
71 snprintf(buffer, sizeof(buffer), "path [%d/%d]", index+1, total);
73 log_coordinates("", buffer, coordinates);
74 maps_coordinates_destroy(coordinates);
78 static bool __maps_route_segment_path_cb(int index, int total, maps_coordinates_h coordinates, void *user_data)
80 if (!coordinates) return false;
83 snprintf(buffer, sizeof(buffer), "path [%d/%d]", index+1, total);
85 log_coordinates(LOG_PREFIX, buffer, coordinates);
86 maps_coordinates_destroy(coordinates);
91 static bool __maps_route_segment_cb(int index, int total, maps_route_segment_h segment, void *user_data)
94 LOG_START("segment [%d/%d] = {", index+1, total);
97 if (maps_route_segment_get_distance(segment, &distance) == MAPS_ERROR_NONE && distance > 0)
98 LOG_PRINT("%sdistance = %.2f %s", LOG_PREFIX, distance, get_distance_unit_string(g_distance_unit));
101 if (maps_route_segment_get_duration(segment, &duration) == MAPS_ERROR_NONE && duration > 0)
102 LOG_PRINT("%sduration = %ld sec", LOG_PREFIX, duration);
104 maps_coordinates_h origin;
105 if (maps_route_segment_get_origin(segment, &origin) == MAPS_ERROR_NONE) {
106 log_coordinates(LOG_PREFIX, "origin", origin);
107 maps_coordinates_destroy(origin);
110 maps_coordinates_h destination;
111 if (maps_route_segment_get_destination(segment, &destination) == MAPS_ERROR_NONE) {
112 log_coordinates(LOG_PREFIX, "destination", destination);
113 maps_coordinates_destroy(destination);
117 if (maps_route_segment_get_bounding_box(segment, &area) == MAPS_ERROR_NONE) {
118 log_area(LOG_PREFIX, area);
119 maps_area_destroy(area);
122 maps_route_segment_foreach_maneuver(segment, __maps_route_segment_maneuver_cb, user_data);
124 maps_route_segment_foreach_path(segment, __maps_route_segment_path_cb, user_data);
126 maps_route_segment_destroy(segment);
133 static bool __log_route(maps_route_h route, void *user_data)
138 if (maps_route_get_route_id(route, &lv.strval) == MAPS_ERROR_NONE)
139 LOG_PRINT("route_id = %s", lv.strval);
141 maps_coordinates_h coord;
143 if (maps_route_get_origin(route, &coord) == MAPS_ERROR_NONE) {
144 maps_coordinates_get_latitude_longitude(coord, &lat, &lon);
145 maps_coordinates_destroy(coord);
146 LOG_PRINT("origin = %f, %f", lat, lon);
148 if (maps_route_get_destination(route, &coord) == MAPS_ERROR_NONE) {
149 maps_coordinates_get_latitude_longitude(coord, &lat, &lon);
150 maps_coordinates_destroy(coord);
151 LOG_PRINT("destination = %f, %f", lat, lon);
154 if (maps_route_get_distance_unit(route, (maps_distance_unit_e*)&lv.intval) == MAPS_ERROR_NONE) {
155 g_distance_unit = lv.intval;
156 LOG_PRINT("distance_unit = '%s' (%d)", get_distance_unit_string(lv.intval), lv.intval);
159 if (maps_route_get_total_distance(route, &lv.dblval) == MAPS_ERROR_NONE)
160 LOG_PRINT("distance = %.2f %s", lv.dblval, get_distance_unit_string(g_distance_unit));
162 if (maps_route_get_total_duration(route, &lv.longval) == MAPS_ERROR_NONE)
163 LOG_PRINT("duration = %ld sec", lv.longval);
165 if (maps_route_get_transport_mode(route, (maps_route_transport_mode_e*)&lv.intval) == MAPS_ERROR_NONE)
166 LOG_PRINT("transport = %s", get_transport_string(lv.intval));
168 maps_area_h area = NULL;
169 if (maps_route_get_bounding_box(route, &area) == MAPS_ERROR_NONE) {
171 maps_area_destroy(area);
174 maps_route_foreach_path(route, __maps_route_path_cb, user_data);
176 maps_route_foreach_segment(route, __maps_route_segment_cb, user_data);
185 * query functions to use APIs
188 static bool __maps_service_search_route_cb(maps_error_e error,
189 int request_id, int index,
190 int total, maps_route_h route,
194 LOG_START_TITLE("%s [%d/%d] ", (user_data ? (char*)user_data : __FUNCTION__), MIN(index+1, total), total);
201 __log_route(route, user_data);
202 maps_route_destroy(route);
206 if (index == total - 1)
212 int maps_test_search_route(maps_service_h maps_svc)
215 int request_id, error;
217 maps_coordinates_h origin = NULL, dest = NULL;
218 maps_coordinates_create(52.525324, 13.369911, &origin);
219 maps_coordinates_create(52.469051, 13.441912, &dest);
221 error = maps_service_search_route(maps_svc, origin, dest, maps_pref,
222 __maps_service_search_route_cb, "Search Route", &request_id);
224 maps_coordinates_destroy(origin);
225 maps_coordinates_destroy(dest);
227 if (error != MAPS_ERROR_NONE)