2 #include "maps_test_geocode.h"
3 #include "maps_test_log.h"
4 #include "maps_test_util.h"
15 static void cleanup_callback(int error)
25 * callback functions for APIs
29 static bool __maps_test_geocode_cb(maps_error_e error, int request_id,
30 int index, int total, maps_coordinates_h coord, void *user_data)
33 LOG_START_TITLE("%s [%d/%d] ", (user_data ? (char*)user_data : __FUNCTION__), MIN(index+1, total), total);
36 cleanup_callback(error);
40 log_coordinates("", "Geocoding", coord);
41 maps_coordinates_destroy(coord);
44 if (index == total - 1)
45 cleanup_callback(error);
49 int maps_test_geocode(maps_service_h maps_svc)
52 int request_id = 0, error;
54 error = maps_service_geocode(maps_svc, "Berlin", maps_pref, __maps_test_geocode_cb, "Geocoding with Berlin", &request_id);
56 if (error != MAPS_ERROR_NONE)
61 static void __maps_test_reverse_geocode_cb(maps_error_e error, int request_id,
62 int index, int total, maps_address_h address, void *user_data)
65 LOG_START_TITLE("%s [%d/%d] ", (user_data ? (char*)user_data : __FUNCTION__), MIN(index+1, total), total);
68 cleanup_callback(error);
72 log_address("", address);
73 maps_address_destroy(address);
76 if (index == total - 1)
77 cleanup_callback(error);
80 int maps_test_reverse_geocode(maps_service_h maps_svc)
83 int request_id = 0, error;
85 error = maps_service_reverse_geocode(maps_svc, 12.944594, 77.554303, maps_pref,
86 __maps_test_reverse_geocode_cb, "Reverse-geocoding with [12.944594, 77.554303]", &request_id);
88 if (error != MAPS_ERROR_NONE)
101 static bool __maps_test_multi_reverse_geocode_cb(maps_error_e error, int request_id, int total,
102 maps_address_list_h address_list, void *user_data)
106 LOG_START_TITLE("%s [%d] ", (user_data ? (char*)user_data : __FUNCTION__), total);
109 cleanup_callback(error);
113 log_address("", address_list);
114 maps_address_list_destroy(address_list);
117 cleanup_callback(error);
121 int maps_test_multi_reverse_geocode(maps_service_h maps_svc)
124 int request_id = 0, error;
126 maps_coordinates_h coordinates[3];
127 maps_coordinates_create(52.5309, 13.3845, &coordinates[0]);
128 maps_coordinates_create(50.1618996, 8.5334997, &coordinates[1]);
129 maps_coordinates_create(40.72962607104243, -73.98685008095087, &coordinates[2]);
131 maps_coordinates_list_h coordinates_list;
132 maps_coordinates_list_create(&coordinates_list);
133 maps_coordinates_list_append(coordinates_list, coordinates[0]);
134 maps_coordinates_list_append(coordinates_list, coordinates[1]);
135 maps_coordinates_list_append(coordinates_list, coordinates[2]);
137 error = maps_service_multi_reverse_geocode(maps_svc, coordinates_list, maps_pref,
138 __maps_test_multi_reverse_geocode_cb, "Multi-reverse Geocoding", &request_id);
139 maps_coordinates_list_destroy(coordinates_list);
141 if (error != MAPS_ERROR_NONE)