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.
19 #include "mapquest_plugin.h"
20 #include "mapquest_plugin_internal.h"
21 #include "mapquest_api.h"
22 #include <maps_error.h>
23 #include <maps_route_plugin.h>
24 #include <maps_route_segment_plugin.h>
25 #include <maps_route_maneuver_plugin.h>
26 #include <maps_place_plugin.h>
27 #include <maps_place_category.h>
28 #include <maps_place_image_plugin.h>
29 #include <maps_place_rating_plugin.h>
31 #define DEFAULT_NUM_RESULTS 10
32 #define _PROVIDER_KEY_MAX_SIZE 1024
34 static const double LATITUDE_RANGE = 85.05113;
35 static const double LONGITUDE_RANGE = 180.0;
37 static int __request_id = 0;
38 static maps_plugin_h __plugin = NULL;
39 static char __provider_key[_PROVIDER_KEY_MAX_SIZE] = { 0 };
41 static maps_item_hashtable_h preference_plugin = NULL;
43 int __maps_service_instance_count = 0;
45 static int __convert_to_maps_error(int ret)
48 case MAPQUEST_ERROR_NONE:
49 return MAPS_ERROR_NONE;
50 case MAPQUEST_ERROR_PERMISSION_DENIED:
51 return MAPS_ERROR_PERMISSION_DENIED;
52 case MAPQUEST_ERROR_OUT_OF_MEMORY:
53 return MAPS_ERROR_OUT_OF_MEMORY;
54 case MAPQUEST_ERROR_INVALID_PARAMETER:
55 return MAPS_ERROR_INVALID_PARAMETER;
56 case MAPQUEST_ERROR_NOT_SUPPORTED:
57 return MAPS_ERROR_NOT_SUPPORTED;
58 case MAPQUEST_ERROR_CONNECTION_TIMED_OUT:
59 return MAPS_ERROR_CONNECTION_TIME_OUT;
60 case MAPQUEST_ERROR_NETWORK_UNREACHABLE:
61 return MAPS_ERROR_NETWORK_UNREACHABLE;
62 case MAPQUEST_ERROR_INVALID_OPERATION:
63 return MAPS_ERROR_INVALID_OPERATION;
64 case MAPQUEST_ERROR_KEY_NOT_AVAILABLE:
65 return MAPS_ERROR_KEY_NOT_AVAILABLE;
66 case MAPQUEST_ERROR_RESOURCE_BUSY:
67 return MAPS_ERROR_RESOURCE_BUSY;
68 case MAPQUEST_ERROR_CANCELED:
69 return MAPS_ERROR_CANCELED;
70 case MAPQUEST_ERROR_UNKNOWN:
71 return MAPS_ERROR_UNKNOWN;
72 case MAPQUEST_ERROR_SERVICE_NOT_AVAILABLE:
73 return MAPS_ERROR_SERVICE_NOT_AVAILABLE;
74 case MAPQUEST_ERROR_NOT_FOUND:
75 return MAPS_ERROR_NOT_FOUND;
77 return MAPS_ERROR_UNKNOWN;
81 static maps_route_turn_type_e __convert_route_turn_type(int index)
83 maps_route_turn_type_e type = MAPS_ROUTE_TURN_TYPE_NONE;
86 type = MAPS_ROUTE_TURN_TYPE_STRAIGHT;
88 type = MAPS_ROUTE_TURN_TYPE_LIGHT_RIGHT;
90 type = MAPS_ROUTE_TURN_TYPE_RIGHT;
92 type = MAPS_ROUTE_TURN_TYPE_HARD_RIGHT;
94 type = MAPS_ROUTE_TURN_TYPE_HARD_LEFT;
96 type = MAPS_ROUTE_TURN_TYPE_LIGHT_LEFT;
98 type = MAPS_ROUTE_TURN_TYPE_LIGHT_LEFT;
100 type = MAPS_ROUTE_TURN_TYPE_UTURN_RIGHT;
102 type = MAPS_ROUTE_TURN_TYPE_UTURN_LEFT;
103 else if (index == 16)
104 type = MAPS_ROUTE_TURN_TYPE_RIGHT_FORK;
105 else if (index == 17)
106 type = MAPS_ROUTE_TURN_TYPE_LEFT_FORK;
107 else if (index == 18)
108 type = MAPS_ROUTE_TURN_TYPE_STRAIGHT_FORK;
110 type = MAPS_ROUTE_TURN_TYPE_NONE;
115 static bool __replace_space(char *place_name, char **modified_place_name)
117 if (!place_name) return false;
121 for (ch = place_name; *ch != '\0'; ch++) {
127 if (strlen(place_name) < new_str_len) {
128 *modified_place_name = (char *)g_malloc((new_str_len + 1) * sizeof(char));
129 if (*modified_place_name) {
131 for (ch1 = place_name, ch2 = *modified_place_name; *ch1 != '\0'; ch1++) {
150 EXPORT_API int maps_plugin_init(maps_plugin_h *plugin)
153 return MAPS_ERROR_INVALID_PARAMETER;
155 int ret = MAPS_ERROR_NONE;
157 ret = mapquest_init();
160 if (ret == MAPS_ERROR_NONE) {
161 __maps_service_instance_count++;
165 return __convert_to_maps_error(ret);
168 EXPORT_API int maps_plugin_shutdown(maps_plugin_h plugin)
170 MAPS_LOGD("PLUGIN SHUTDOWN");
172 return MAPS_ERROR_INVALID_PARAMETER;
174 __maps_service_instance_count--;
176 int ret = MAPS_ERROR_NONE;
177 if (__maps_service_instance_count == 0) {
178 ret = mapquest_shutdown();
182 return __convert_to_maps_error(ret);
185 EXPORT_API int maps_plugin_is_service_supported(maps_service_e service, bool *supported)
188 return MAPS_ERROR_INVALID_PARAMETER;
191 case MAPS_SERVICE_GEOCODE:
192 case MAPS_SERVICE_GEOCODE_INSIDE_AREA:
193 case MAPS_SERVICE_GEOCODE_BY_STRUCTURED_ADDRESS:
194 case MAPS_SERVICE_REVERSE_GEOCODE:
195 case MAPS_SERVICE_SEARCH_PLACE:
196 case MAPS_SERVICE_SEARCH_PLACE_BY_AREA:
197 case MAPS_SERVICE_SEARCH_PLACE_BY_ADDRESS:
198 case MAPS_SERVICE_SEARCH_ROUTE:
199 case MAPS_SERVICE_SEARCH_ROUTE_WAYPOINTS:
200 case MAPS_SERVICE_CANCEL_REQUEST:
202 return MAPS_ERROR_NONE;
205 return MAPS_ERROR_NOT_SUPPORTED;
209 EXPORT_API int maps_plugin_is_data_supported(maps_service_data_e data, bool *supported)
212 return MAPS_ERROR_INVALID_PARAMETER;
215 case MAPS_PLACE_ADDRESS:
216 case MAPS_PLACE_CATEGORIES:
217 case MAPS_PLACE_IMAGE:
219 /* case MAPS_PLACE_RATING: */
220 /* case MAPS_PLACE_ATTRIBUTES: */
221 /* case MAPS_PLACE_CONTACTS: */
222 /* case MAPS_PLACE_EDITORIALS: */
223 /* case MAPS_PLACE_REVIEWS: */
224 /* case MAPS_PLACE_SUPPLIER: */
225 /* case MAPS_PLACE_RELATED: */
227 case MAPS_ROUTE_PATH:
228 case MAPS_ROUTE_SEGMENTS_PATH:
229 case MAPS_ROUTE_SEGMENTS_MANEUVERS:
231 return MAPS_ERROR_NONE;
234 return MAPS_ERROR_NOT_SUPPORTED;
238 EXPORT_API int maps_plugin_get_info(maps_plugin_info_h *info)
241 return MAPS_ERROR_INVALID_PARAMETER;
243 maps_plugin_info_create(info);
244 maps_plugin_info_set_provider_name(*info, "MAPQUEST");
246 return MAPS_ERROR_NONE;
249 EXPORT_API int maps_plugin_set_provider_key(const char *provider_key)
252 return MAPS_ERROR_INVALID_PARAMETER;
254 g_snprintf(__provider_key, _PROVIDER_KEY_MAX_SIZE, "%s", provider_key);
256 return MAPS_ERROR_NONE;
259 EXPORT_API int maps_plugin_get_provider_key(char **provider_key)
262 return MAPS_ERROR_INVALID_PARAMETER;
264 *provider_key = g_strndup(__provider_key, _PROVIDER_KEY_MAX_SIZE);
266 return MAPS_ERROR_NONE;
269 EXPORT_API int maps_plugin_set_preference(maps_item_hashtable_h preference)
272 return MAPS_ERROR_INVALID_PARAMETER;
274 maps_item_hashtable_clone(preference, &preference_plugin);
275 return MAPS_ERROR_NONE;
278 EXPORT_API int maps_plugin_get_preference(maps_item_hashtable_h *preference)
281 return MAPS_ERROR_INVALID_PARAMETER;
283 maps_item_hashtable_clone(preference_plugin, preference);
284 return MAPS_ERROR_NONE;
287 static void __mapquest_geocode_cb(mapquest_error_e result, int request_id, GList *co_ordinates, void *user_data)
289 MAPS_LOGD("Got GEOCODE callback from ENGINE");
291 callback_info_geocode *calldata_geocode = (callback_info_geocode *) user_data;
293 if ((result != MAPQUEST_ERROR_NONE) || (co_ordinates == NULL)) {
294 MAPS_LOGD(">>>>> Invalid GEOCODE result <<<<<");
295 calldata_geocode->callback((maps_error_e)__convert_to_maps_error(result), calldata_geocode->reqID, 0, 0, NULL, calldata_geocode->data);
297 int total_count = (int) g_list_length(co_ordinates);
300 GList *coords = NULL;
301 coords = g_list_first(co_ordinates);
304 MAPS_LOGD("coordinate %d", index);
305 coords_s *data = (coords_s *) coords->data;
308 maps_coordinates_h resultCoords;
309 maps_coordinates_create(data->latitude, data->longitude, &resultCoords);
310 bool b = calldata_geocode->callback(MAPS_ERROR_NONE, calldata_geocode->reqID, index, total_count, resultCoords, calldata_geocode->data);
315 coords = coords->next;
320 EXPORT_API int maps_plugin_geocode(const char *address, const maps_preference_h preference, maps_service_geocode_cb callback, void *user_data, int *request_id)
322 if (!address || !callback || !request_id)
323 return MAPS_ERROR_INVALID_PARAMETER;
325 callback_info_geocode *calldata_geocode = (callback_info_geocode *)g_malloc0(sizeof(callback_info_geocode));
326 if (calldata_geocode == NULL)
327 MAPS_PRINT_ERROR_CODE_RETURN(MAPS_ERROR_OUT_OF_MEMORY);
329 calldata_geocode->callback = callback;
330 calldata_geocode->data = user_data;
332 mapquest_geocode_req_s *geocode_req = (mapquest_geocode_req_s *)g_malloc0(sizeof(mapquest_geocode_req_s));
333 if (geocode_req == NULL) {
334 g_free(calldata_geocode);
335 calldata_geocode = NULL;
336 MAPS_PRINT_ERROR_CODE_RETURN(MAPS_ERROR_OUT_OF_MEMORY);
339 char *modified_address = NULL;
340 bool b_isAddress_modified = false;
341 b_isAddress_modified = __replace_space((char *)address, &modified_address);
343 if (b_isAddress_modified)
344 geocode_req->address = g_strdup((gchar *) modified_address);
346 geocode_req->address = g_strdup((gchar *) address);
348 if (modified_address) {
349 g_free(modified_address);
350 modified_address = NULL;
353 geocode_req->maps_key = g_strdup((gchar *) __provider_key);
354 geocode_req->boundary = NULL;
357 maps_preference_get_max_results(preference, &max_result);
360 geocode_req->num_res = DEFAULT_NUM_RESULTS;
362 geocode_req->num_res = max_result;
364 *request_id = ++__request_id;
365 calldata_geocode->reqID = __request_id;
367 int ret = mapquest_geocode(geocode_req, __mapquest_geocode_cb, __request_id, (void *) calldata_geocode);
369 return __convert_to_maps_error(ret);
372 EXPORT_API int maps_plugin_geocode_inside_area(const char *address, const maps_area_h bounds, const maps_preference_h preference, maps_service_geocode_cb callback, void *user_data, int *request_id)
374 if (!bounds || !address || !callback || !request_id)
375 return MAPS_ERROR_INVALID_PARAMETER;
377 callback_info_geocode *calldata_geocode = (callback_info_geocode *)g_malloc0(sizeof(callback_info_geocode));
378 if (calldata_geocode == NULL)
379 MAPS_PRINT_ERROR_CODE_RETURN(MAPS_ERROR_OUT_OF_MEMORY);
381 calldata_geocode->callback = callback;
382 calldata_geocode->data = user_data;
384 mapquest_geocode_req_s *geocode_req = (mapquest_geocode_req_s *)g_malloc0(sizeof(mapquest_geocode_req_s));
385 if (geocode_req == NULL) {
386 free(calldata_geocode);
387 MAPS_PRINT_ERROR_CODE_RETURN(MAPS_ERROR_OUT_OF_MEMORY);
390 char *modified_address = NULL;
391 bool b_isAddress_modified = false;
392 b_isAddress_modified = __replace_space((char *)address, &modified_address);
394 if (b_isAddress_modified)
395 geocode_req->address = g_strdup((gchar *) modified_address);
397 geocode_req->address = g_strdup((gchar *) address);
399 if (modified_address) {
400 g_free(modified_address);
401 modified_address = NULL;
404 geocode_req->maps_key = g_strdup((gchar *) __provider_key);
407 maps_preference_get_max_results(preference, &max_result);
410 geocode_req->num_res = DEFAULT_NUM_RESULTS;
412 geocode_req->num_res = max_result;
414 geocode_req->boundary = NULL;
415 geocode_req->boundary = (mapquest_boundary_s *)g_malloc0(sizeof(mapquest_boundary_s));
417 maps_area_s *area = (maps_area_s *) bounds;
419 if (area && geocode_req->boundary) {
420 if (area->type == MAPS_AREA_RECTANGLE) {
421 geocode_req->boundary->type = MAPQUEST_BOUNDARY_RECT;
422 geocode_req->boundary->rect.top_left.latitude = area->rect.top_left.latitude;
423 geocode_req->boundary->rect.top_left.longitude = area->rect.top_left.longitude;
424 geocode_req->boundary->rect.bottom_right.latitude = area->rect.bottom_right.latitude;
425 geocode_req->boundary->rect.bottom_right.longitude = area->rect.bottom_right.longitude;
426 } else if (area->type == MAPS_AREA_CIRCLE) {
427 geocode_req->boundary->type = MAPQUEST_BOUNDARY_CIRCLE;
428 geocode_req->boundary->circle.center.latitude = area->circle.center.latitude;
429 geocode_req->boundary->circle.center.longitude = area->circle.center.longitude;
430 geocode_req->boundary->circle.radius = area->circle.radius;
434 *request_id = ++__request_id;
435 calldata_geocode->reqID = __request_id;
437 int ret = mapquest_geocode(geocode_req, __mapquest_geocode_cb, __request_id, (void *) calldata_geocode);
439 return __convert_to_maps_error(ret);
442 EXPORT_API int maps_plugin_geocode_by_structured_address(const maps_address_h address, const maps_preference_h preference, maps_service_geocode_cb callback, void *user_data, int *request_id)
444 if (!address || !callback || !request_id)
445 return MAPS_ERROR_INVALID_PARAMETER;
447 callback_info_geocode *calldata_geocode = (callback_info_geocode *)g_malloc0(sizeof(callback_info_geocode));
448 if (calldata_geocode == NULL)
449 MAPS_PRINT_ERROR_CODE_RETURN(MAPS_ERROR_OUT_OF_MEMORY);
451 calldata_geocode->callback = callback;
452 calldata_geocode->data = user_data;
454 mapquest_geocode_req_s *geocode_req = (mapquest_geocode_req_s *)g_malloc0(sizeof(mapquest_geocode_req_s));
455 if (geocode_req == NULL) {
456 free(calldata_geocode);
457 MAPS_PRINT_ERROR_CODE_RETURN(MAPS_ERROR_OUT_OF_MEMORY);
460 char resultAddressQuery[1024];
461 strcpy(resultAddressQuery, "");
464 maps_address_get_street(address, &street);
466 strcat(resultAddressQuery, street);
469 maps_address_get_city(address, &city);
470 if ((strlen(resultAddressQuery) > 0) && (city != NULL)) {
471 strcat(resultAddressQuery, ",");
472 strcat(resultAddressQuery, city);
473 } else if (city != NULL) {
474 strcat(resultAddressQuery, city);
478 maps_address_get_state(address, &state);
479 if ((strlen(resultAddressQuery) > 0) && (state != NULL)) {
480 strcat(resultAddressQuery, ",");
481 strcat(resultAddressQuery, state);
482 } else if (state != NULL) {
483 strcat(resultAddressQuery, state);
487 char *district = NULL;
488 maps_address_get_district(address, &district);
489 if ((strlen(resultAddressQuery) > 0) && (district != NULL)) {
490 strcat(resultAddressQuery, ", ");
491 strcat(resultAddressQuery, district);
494 char *country = NULL;
495 maps_address_get_country(address, &country);
496 if ((strlen(resultAddressQuery) > 0) && (country != NULL)) {
497 strcat(resultAddressQuery, ", ");
498 strcat(resultAddressQuery, country);
501 char *country_code = NULL;
502 maps_address_get_country_code(address, &country_code);
503 if ((strlen(resultAddressQuery) > 0) && (country_code != NULL)) {
504 strcat(resultAddressQuery, ", ");
505 strcat(resultAddressQuery, country_code);
506 } else if (country_code != NULL) {
507 strcat(resultAddressQuery, country_code);
511 maps_address_get_county(address, &county);
512 if ((strlen(resultAddressQuery) > 0) && (county != NULL)) {
513 strcat(resultAddressQuery, ", ");
514 strcat(resultAddressQuery, county);
518 char *postal_code = NULL;
519 maps_address_get_postal_code(address, &postal_code);
520 if ((strlen(resultAddressQuery) > 0) && (postal_code != NULL)) {
521 strcat(resultAddressQuery, ",");
522 strcat(resultAddressQuery, postal_code);
523 } else if (postal_code != NULL) {
524 strcat(resultAddressQuery, postal_code);
527 char *modified_address = NULL;
528 bool b_isAddress_modified = false;
529 b_isAddress_modified = __replace_space(resultAddressQuery, &modified_address);
531 if (b_isAddress_modified)
532 geocode_req->address = g_strdup((gchar *) modified_address);
534 geocode_req->address = g_strdup((gchar *) resultAddressQuery);
536 if (modified_address) {
537 g_free(modified_address);
538 modified_address = NULL;
541 geocode_req->maps_key = g_strdup((gchar *) __provider_key);
542 geocode_req->boundary = NULL;
545 maps_preference_get_max_results(preference, &max_result);
548 geocode_req->num_res = DEFAULT_NUM_RESULTS;
550 geocode_req->num_res = max_result;
552 *request_id = ++__request_id;
553 calldata_geocode->reqID = __request_id;
555 int ret = mapquest_geocode(geocode_req, __mapquest_geocode_cb, __request_id, (void *) calldata_geocode);
557 return __convert_to_maps_error(ret);
560 static void __mapquest_reverse_geocode_cb(mapquest_error_e result, int request_id, mapquest_address_resp_s *address, void *user_data)
562 MAPS_LOGD("Got REV GEOCODE callback from ENGINE");
563 callback_info_reverse_geocode *calldata_reverse_geocode = (callback_info_reverse_geocode *) user_data;
564 if (result != MAPQUEST_ERROR_NONE || address == NULL) {
565 calldata_reverse_geocode->callback((maps_error_e) __convert_to_maps_error(result), calldata_reverse_geocode->reqID, 0, 0, NULL, calldata_reverse_geocode->data);
570 maps_address_h addr = NULL;
571 maps_address_create(&addr);
573 maps_address_set_street(addr, address->street_add);
574 maps_address_set_city(addr, address->city);
575 maps_address_set_county(addr, address->county);
576 maps_address_set_state(addr, address->state);
577 maps_address_set_country(addr, address->country);
578 maps_address_set_country_code(addr, address->country_code);
579 maps_address_set_postal_code(addr, address->postal_code);
581 calldata_reverse_geocode->callback(MAPS_ERROR_NONE, calldata_reverse_geocode->reqID, index, total_count, addr, calldata_reverse_geocode->data);
585 EXPORT_API int maps_plugin_reverse_geocode(double latitude, double longitude, const maps_preference_h preference, maps_service_reverse_geocode_cb callback, void *user_data, int *request_id)
587 if (!callback || !request_id)
588 return MAPS_ERROR_INVALID_PARAMETER;
590 if (latitude > LATITUDE_RANGE || latitude < -LATITUDE_RANGE)
591 return MAPS_ERROR_INVALID_PARAMETER;
593 if (longitude > LONGITUDE_RANGE || longitude < -LONGITUDE_RANGE)
594 return MAPS_ERROR_INVALID_PARAMETER;
596 callback_info_reverse_geocode *calldata_reverse_geocode = (callback_info_reverse_geocode *)g_malloc0(sizeof(callback_info_reverse_geocode));
597 if (calldata_reverse_geocode == NULL)
598 MAPS_PRINT_ERROR_CODE_RETURN(MAPS_ERROR_OUT_OF_MEMORY);
600 calldata_reverse_geocode->callback = callback;
601 calldata_reverse_geocode->data = user_data;
603 mapquest_revgeocode_req_s *reverse_geocode_req = (mapquest_revgeocode_req_s *)g_malloc0(sizeof(mapquest_revgeocode_req_s));
604 if (reverse_geocode_req == NULL) {
605 g_free(calldata_reverse_geocode);
606 calldata_reverse_geocode = NULL;
607 MAPS_PRINT_ERROR_CODE_RETURN(MAPS_ERROR_OUT_OF_MEMORY);
610 reverse_geocode_req->maps_key = g_strdup((gchar *) __provider_key);
611 reverse_geocode_req->coordinates.latitude = latitude;
612 reverse_geocode_req->coordinates.longitude = longitude;
614 *request_id = ++__request_id;
615 calldata_reverse_geocode->reqID = __request_id;
617 int ret = mapquest_reverse_geocode(reverse_geocode_req, __mapquest_reverse_geocode_cb, __request_id, (void *) calldata_reverse_geocode);
619 return __convert_to_maps_error(ret);
622 static void __mapquest_route_cb(mapquest_error_e result, int request_id, mapquest_route_resp_s *route_info, void *user_data)
624 MAPS_LOGD("__mapquest_route_cb");
625 callback_info_route *calldata_route = (callback_info_route *) user_data;
629 maps_route_create(&route);
631 maps_coordinates_h top_left;
632 maps_coordinates_create(route_info->bounding_box.top_left.latitude, route_info->bounding_box.top_left.longitude, &top_left);
634 maps_coordinates_h bottom_right;
635 maps_coordinates_create(route_info->bounding_box.bottom_right.latitude, route_info->bounding_box.bottom_right.longitude, &bottom_right);
637 maps_area_h bounds = NULL;
638 maps_area_create_rectangle(top_left, bottom_right, &bounds);
639 maps_route_set_bounding_box(route, bounds);
640 maps_area_destroy(bounds);
642 maps_coordinates_destroy(top_left);
643 maps_coordinates_destroy(bottom_right);
645 maps_distance_unit_e unit = MAPS_DISTANCE_UNIT_M;
647 switch (route_info->distance_unit) {
649 unit = MAPS_DISTANCE_UNIT_M;
652 unit = MAPS_DISTANCE_UNIT_KM;
655 unit = MAPS_DISTANCE_UNIT_FT;
658 unit = MAPS_DISTANCE_UNIT_YD;
662 maps_route_set_distance_unit(route, unit);
663 maps_route_set_total_distance(route, route_info->distance);
664 maps_route_set_total_duration(route, (long) route_info->time);
665 if (route_info->type == ROUTE_TYPE_FASTEST)
666 maps_route_set_transport_mode(route, MAPS_ROUTE_TRANSPORT_MODE_CAR);
667 else if (route_info->type == ROUTE_TYPE_PEDESTRIAN)
668 maps_route_set_transport_mode(route, MAPS_ROUTE_TRANSPORT_MODE_PEDESTRIAN);
669 else if (route_info->type == ROUTE_TYPE_BICYCLE)
670 maps_route_set_transport_mode(route, MAPS_ROUTE_TRANSPORT_MODE_BICYCLE);
671 else if (route_info->type == ROUTE_TYPE_MULTIMODAL)
672 maps_route_set_transport_mode(route, MAPS_ROUTE_TRANSPORT_MODE_PUBLICTRANSIT);
674 maps_route_set_transport_mode(route, MAPS_ROUTE_TRANSPORT_MODE_CAR);
676 maps_item_list_h segment_list = NULL;
677 maps_item_list_create(&segment_list);
679 GList *maneuver_data = NULL;
680 maneuver_data = g_list_first(route_info->maneuvers);
682 while (maneuver_data) {
683 maps_route_segment_h segment = NULL;
684 maps_route_segment_create(&segment);
686 maps_route_maneuver_h man = NULL;
687 maps_route_maneuver_create(&man);
688 mapquest_route_maneuver *maneuver = (mapquest_route_maneuver *) maneuver_data->data;
690 /* Segment Origin and Destination */
691 maps_coordinates_h segmentStartPoint;
692 maps_coordinates_create(maneuver->start_point.latitude, maneuver->start_point.longitude, &segmentStartPoint);
693 maps_route_segment_set_origin(segment, segmentStartPoint); /* origin */
694 maps_coordinates_destroy(segmentStartPoint);
696 maps_coordinates_h segmentEndPoint;
697 maps_coordinates_create(maneuver->end_point.latitude, maneuver->end_point.longitude, &segmentEndPoint);
699 MAPS_LOGD(">>> Segment start : %f, %f <<<", maneuver->start_point.latitude, maneuver->start_point.longitude);
700 MAPS_LOGD(">>> Segment end : %f, %f <<<", maneuver->end_point.latitude, maneuver->end_point.longitude);
702 maps_route_segment_set_destination(segment, segmentEndPoint); /* destination */
703 maps_coordinates_destroy(segmentEndPoint);
705 /* Segment distance */
706 maps_route_segment_set_distance(segment, maneuver->distance);
707 maps_route_segment_set_duration(segment, maneuver->time);
709 /* Maneuver distance */
710 maps_route_maneuver_set_distance_to_next_instruction(man, maneuver->distance);
711 maps_route_maneuver_set_time_to_next_instruction(man, maneuver->time);
713 maps_route_maneuver_set_turn_type(man, __convert_route_turn_type(maneuver->turn_type));
715 /* maneuver_set_traffic_direction(man, (traffic_direction_e)action_id); */
717 /* Maneuver Instruction */
718 if (maneuver->instruction)
719 maps_route_maneuver_set_instruction_text(man, (char *) maneuver->instruction);
721 /* Maneuver Street Name */
722 if (maneuver->street_name) {
723 MAPS_LOGD("Street Name >>>> %s", maneuver->street_name);
724 maps_route_maneuver_set_road_name(man, (char *) maneuver->street_name);
726 MAPS_LOGD("Street Name >>>> NIL");
729 /* Maneuver start position */
730 maps_coordinates_h coord;
731 maps_coordinates_create(maneuver->start_point.latitude, maneuver->start_point.longitude, &coord);
733 maps_route_maneuver_set_position(man, coord);
734 maps_coordinates_destroy(coord);
736 maps_item_list_h maneuver_list = NULL;
737 maps_item_list_create(&maneuver_list);
738 maps_item_list_append(maneuver_list, (gpointer) man, maps_route_maneuver_clone);
739 maps_route_segment_set_maneuvers(segment, maneuver_list);
741 maps_item_list_destroy(maneuver_list);
742 maps_route_maneuver_destroy(man);
744 maps_item_list_append(segment_list, (gpointer) segment, maps_route_segment_clone);
745 maps_route_segment_destroy(segment);
747 /* Fetching the next item from Maneuver/Segment list */
748 maneuver_data = g_list_next(maneuver_data);
750 maps_route_set_segments(route, segment_list);
751 maps_item_list_destroy(segment_list);
753 /* Shape points - path */
754 maps_item_list_h path_list = NULL;
755 maps_item_list_create(&path_list);
757 GList *shapePoints = NULL;
758 shapePoints = g_list_first(route_info->shapePoints);
760 while (shapePoints) {
761 coords_s *data = (coords_s *) shapePoints->data;
763 maps_coordinates_h shapeCoords;
764 maps_coordinates_create(data->latitude, data->longitude, &shapeCoords);
766 maps_item_list_append(path_list, (gpointer) shapeCoords, maps_coordinates_clone);
768 maps_coordinates_destroy(shapeCoords);
770 shapePoints = g_list_next(shapePoints);
772 maps_route_set_path(route, path_list);
773 maps_item_list_destroy(path_list);
775 bool b = calldata_route->callback((maps_error_e)__convert_to_maps_error(result), calldata_route->reqID, 0, 1, route, calldata_route->data);
779 calldata_route->callback((maps_error_e)__convert_to_maps_error(result), calldata_route->reqID, 0, 0, NULL, calldata_route->data);
783 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)
785 if (!origin || !destination || !callback || !request_id)
786 return MAPS_ERROR_INVALID_PARAMETER;
788 callback_info_route *calldata_route = (callback_info_route *)g_malloc0(sizeof(callback_info_route));
789 if (calldata_route == NULL)
790 MAPS_PRINT_ERROR_CODE_RETURN(MAPS_ERROR_OUT_OF_MEMORY);
792 calldata_route->callback = callback;
793 calldata_route->data = user_data;
795 mapquest_route_req_s *route_req = (mapquest_route_req_s *)g_malloc0(sizeof(mapquest_route_req_s));
796 if (route_req == NULL) {
797 g_free(calldata_route);
798 calldata_route = NULL;
799 MAPS_PRINT_ERROR_CODE_RETURN(MAPS_ERROR_OUT_OF_MEMORY);
802 route_req->maps_key = g_strdup((gchar *) __provider_key);
804 double origin_lat, origin_lon;
805 double dest_lat, dest_lon;
807 maps_coordinates_get_latitude(origin, &origin_lat);
808 maps_coordinates_get_longitude(origin, &origin_lon);
810 maps_coordinates_get_latitude(destination, &dest_lat);
811 maps_coordinates_get_longitude(destination, &dest_lon);
813 route_req->from.latitude = origin_lat;
814 route_req->from.longitude = origin_lon;
816 route_req->to.latitude = dest_lat;
817 route_req->to.longitude = dest_lon;
819 MAPS_LOGD("getting transport mode..");
820 maps_route_transport_mode_e transport_mode;
821 maps_preference_get_route_transport_mode(preference, &transport_mode);
823 if (transport_mode == MAPS_ROUTE_TRANSPORT_MODE_CAR)
824 route_req->type = ROUTE_TYPE_FASTEST;
825 else if (transport_mode == MAPS_ROUTE_TRANSPORT_MODE_PEDESTRIAN)
826 route_req->type = ROUTE_TYPE_PEDESTRIAN;
827 else if (transport_mode == MAPS_ROUTE_TRANSPORT_MODE_BICYCLE)
828 route_req->type = ROUTE_TYPE_BICYCLE;
829 else if (transport_mode == MAPS_ROUTE_TRANSPORT_MODE_PUBLICTRANSIT)
830 route_req->type = ROUTE_TYPE_MULTIMODAL;
832 route_req->type = ROUTE_TYPE_FASTEST; /* Keeping it as default */
834 route_req->driving_style = DRIVING_STYLE_NORMAL; /* Keeping it as default */
837 maps_distance_unit_e unit;
838 maps_preference_get_distance_unit(preference, &unit);
841 case MAPS_DISTANCE_UNIT_M:
842 route_req->unit = ROUTE_UNIT_M;
844 case MAPS_DISTANCE_UNIT_KM:
845 route_req->unit = ROUTE_UNIT_KM;
847 case MAPS_DISTANCE_UNIT_FT:
848 route_req->unit = ROUTE_UNIT_FT;
850 case MAPS_DISTANCE_UNIT_YD:
851 route_req->unit = ROUTE_UNIT_YD;
855 route_req->avoids = ROUTE_AVOID_NONE;
856 maps_route_feature_weight_e routeWeight;
857 maps_preference_get_route_feature_weight(preference, &routeWeight);
859 if (routeWeight == MAPS_ROUTE_FEATURE_WEIGHT_AVOID) {
860 maps_route_feature_e routeFeature;
861 maps_preference_get_route_feature(preference, &routeFeature);
863 if (routeFeature == MAPS_ROUTE_FEATURE_TOLL)
864 route_req->avoids = ROUTE_AVOID_TOLL_ROAD;
865 else if (routeFeature == MAPS_ROUTE_FEATURE_MOTORWAY)
866 route_req->avoids = ROUTE_AVOID_LIMITED_ACCESS;
867 else if ((routeFeature == MAPS_ROUTE_FEATURE_BOATFERRY) || (routeFeature == MAPS_ROUTE_FEATURE_RAILFERRY))
868 route_req->avoids = ROUTE_AVOID_FERRY;
869 else if (routeFeature == MAPS_ROUTE_FEATURE_DIRTROAD)
870 route_req->avoids = ROUTE_AVOID_UNPAVED;
872 route_req->avoids = ROUTE_AVOID_NONE;
875 route_req->way_points = NULL;
877 *request_id = ++__request_id;
878 calldata_route->reqID = __request_id;
880 int ret = mapquest_start_route(route_req, __mapquest_route_cb, __request_id, (void *)calldata_route);
882 return __convert_to_maps_error(ret);
885 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)
887 if (!waypoint_list || waypoint_num < 2 || !callback || !request_id)
888 return MAPS_ERROR_INVALID_PARAMETER;
890 callback_info_route *calldata_route = (callback_info_route *)g_malloc0(sizeof(callback_info_route));
891 if (calldata_route == NULL)
892 MAPS_PRINT_ERROR_CODE_RETURN(MAPS_ERROR_OUT_OF_MEMORY);
894 calldata_route->callback = callback;
895 calldata_route->data = user_data;
897 mapquest_route_req_s *route_req = (mapquest_route_req_s *)g_malloc0(sizeof(mapquest_route_req_s));
898 if (route_req == NULL) {
899 g_free(calldata_route);
900 calldata_route = NULL;
901 MAPS_PRINT_ERROR_CODE_RETURN(MAPS_ERROR_OUT_OF_MEMORY);
904 route_req->maps_key = g_strdup((gchar *) __provider_key);
906 route_req->from.latitude = 0.0;
907 route_req->from.longitude = 0.0;
909 route_req->to.latitude = 0.0;
910 route_req->to.longitude = 0.0;
912 MAPS_LOGD("getting transport mode..");
913 maps_route_transport_mode_e transport_mode;
914 maps_preference_get_route_transport_mode(preference, &transport_mode);
916 if (transport_mode == MAPS_ROUTE_TRANSPORT_MODE_CAR)
917 route_req->type = ROUTE_TYPE_FASTEST;
918 else if (transport_mode == MAPS_ROUTE_TRANSPORT_MODE_PEDESTRIAN)
919 route_req->type = ROUTE_TYPE_PEDESTRIAN;
920 else if (transport_mode == MAPS_ROUTE_TRANSPORT_MODE_BICYCLE)
921 route_req->type = ROUTE_TYPE_BICYCLE;
922 else if (transport_mode == MAPS_ROUTE_TRANSPORT_MODE_PUBLICTRANSIT)
923 route_req->type = ROUTE_TYPE_MULTIMODAL;
925 route_req->type = ROUTE_TYPE_FASTEST; /* Keeping it as default */
927 route_req->driving_style = DRIVING_STYLE_NORMAL; /* Keeping it as default */
930 maps_distance_unit_e unit;
931 maps_preference_get_distance_unit(preference, &unit);
934 case MAPS_DISTANCE_UNIT_M:
935 route_req->unit = ROUTE_UNIT_M;
937 case MAPS_DISTANCE_UNIT_KM:
938 route_req->unit = ROUTE_UNIT_KM;
940 case MAPS_DISTANCE_UNIT_FT:
941 route_req->unit = ROUTE_UNIT_FT;
943 case MAPS_DISTANCE_UNIT_YD:
944 route_req->unit = ROUTE_UNIT_YD;
948 route_req->avoids = ROUTE_AVOID_NONE;
949 maps_route_feature_weight_e routeWeight;
950 maps_preference_get_route_feature_weight(preference, &routeWeight);
952 if (routeWeight == MAPS_ROUTE_FEATURE_WEIGHT_AVOID) {
953 maps_route_feature_e routeFeature;
954 maps_preference_get_route_feature(preference, &routeFeature);
956 if (routeFeature == MAPS_ROUTE_FEATURE_TOLL)
957 route_req->avoids = ROUTE_AVOID_TOLL_ROAD;
958 else if (routeFeature == MAPS_ROUTE_FEATURE_MOTORWAY)
959 route_req->avoids = ROUTE_AVOID_LIMITED_ACCESS;
960 else if ((routeFeature == MAPS_ROUTE_FEATURE_BOATFERRY) || (routeFeature == MAPS_ROUTE_FEATURE_RAILFERRY))
961 route_req->avoids = ROUTE_AVOID_FERRY;
962 else if (routeFeature == MAPS_ROUTE_FEATURE_DIRTROAD)
963 route_req->avoids = ROUTE_AVOID_UNPAVED;
965 route_req->avoids = ROUTE_AVOID_NONE;
969 route_req->way_points = NULL;
970 if (waypoint_num != 0) {
972 double latitude = 0.0, longitude = 0.0;
973 for (index = 0; index < waypoint_num; index++) {
974 if (waypoint_list[index] != NULL) {
975 maps_coordinates_get_latitude(waypoint_list[index], &latitude);
976 maps_coordinates_get_longitude(waypoint_list[index], &longitude);
978 coords_s *data = (coords_s *)g_malloc0(sizeof(coords_s));
980 data->latitude = latitude;
981 data->longitude = longitude;
983 if (route_req->way_points == NULL)
984 route_req->way_points = g_list_append(route_req->way_points, (gpointer) data);
986 route_req->way_points = g_list_insert_before(route_req->way_points, NULL, (gpointer) data);
992 *request_id = ++__request_id;
993 calldata_route->reqID = __request_id;
995 int ret = mapquest_start_route(route_req, __mapquest_route_cb, __request_id, (void *)calldata_route);
997 return __convert_to_maps_error(ret);
1000 static void __mapquest_place_search_cb(mapquest_error_e result, int request_id, GList *places, void *user_data)
1002 MAPS_LOGD("Got places result from ENGINE...");
1004 callback_info_place *calldata_place = (callback_info_place *) user_data;
1006 if (result != MAPQUEST_ERROR_NONE || places == NULL) {
1007 MAPS_LOGD("Got places result from ENGINE...result is NULL");
1008 calldata_place->callback((maps_error_e) __convert_to_maps_error(result), calldata_place->reqID, 0, 0, NULL, calldata_place->data);
1010 guint total_count = 0;
1012 total_count = g_list_length(places);
1013 if (total_count > 0) {
1014 maps_place_h place = NULL;
1015 MAPS_LOGD("Got places result from ENGINE... count -> %d", total_count);
1017 GList *temp_place = NULL;
1018 temp_place = g_list_first(places);
1020 while (temp_place) {
1021 maps_place_create(&place);
1022 mapquest_place_resp_s *mapquest_place = (mapquest_place_resp_s *) temp_place->data;
1023 maps_place_set_id(place, mapquest_place->place_id);
1024 maps_place_set_name(place, mapquest_place->display_name);
1026 MAPS_LOGD("Before address..");
1028 if (mapquest_place->address) {
1029 maps_address_h addr = NULL;
1030 maps_address_create(&addr);
1032 maps_address_set_street(addr, mapquest_place->address->street_add);
1033 maps_address_set_building_number(addr, mapquest_place->address->building_number);
1034 maps_address_set_city(addr, mapquest_place->address->city);
1035 maps_address_set_county(addr, mapquest_place->address->county);
1036 maps_address_set_state(addr, mapquest_place->address->state);
1037 maps_address_set_country(addr, mapquest_place->address->country);
1038 maps_address_set_country_code(addr, mapquest_place->address->country_code);
1039 maps_address_set_postal_code(addr, mapquest_place->address->postal_code);
1040 maps_address_set_freetext(addr, mapquest_place->display_name);
1042 maps_place_set_address(place, addr);
1043 maps_address_destroy(addr);
1045 maps_place_set_address(place, NULL);
1048 maps_coordinates_h coord;
1049 maps_coordinates_create(mapquest_place->coordinates.latitude, mapquest_place->coordinates.longitude, &coord);
1051 maps_place_set_location(place, coord);
1052 maps_coordinates_destroy(coord);
1054 maps_place_category_h place_cat;
1055 maps_place_category_create(&place_cat);
1056 maps_place_category_set_name(place_cat, mapquest_place->category);
1058 maps_item_list_h cat_list;
1059 maps_item_list_create(&cat_list);
1060 maps_item_list_append(cat_list, (void *) place_cat, maps_place_category_clone);
1061 maps_place_set_categories(place, cat_list);
1063 maps_place_category_destroy(place_cat);
1064 maps_item_list_destroy(cat_list);
1066 maps_place_image_h place_image;
1067 maps_place_image_create(&place_image);
1068 maps_place_image_set_url(place_image, mapquest_place->icon_url);
1069 maps_item_list_h image_list;
1070 maps_item_list_create(&image_list);
1071 maps_item_list_append(image_list, (void *) place_image, maps_place_image_clone);
1072 maps_place_set_images(place, image_list);
1074 maps_place_image_destroy(place_image);
1075 maps_item_list_destroy(image_list);
1077 bool b = calldata_place->callback((maps_error_e)__convert_to_maps_error(result), calldata_place->reqID, index, total_count, place, calldata_place->data);
1083 temp_place = temp_place->next;
1086 calldata_place->callback((maps_error_e)__convert_to_maps_error(result), calldata_place->reqID, index, total_count, NULL, calldata_place->data);
1091 EXPORT_API int maps_plugin_search_place(const maps_coordinates_h position, int distance, const maps_place_filter_h filter, const maps_preference_h preference, maps_service_search_place_cb callback, void *user_data, int *request_id)
1093 if (!position || !filter || !callback || !request_id)
1094 return MAPS_ERROR_INVALID_PARAMETER;
1096 return MAPS_ERROR_INVALID_PARAMETER;
1098 callback_info_place *calldata_place = (callback_info_place *)g_malloc0(sizeof(callback_info_place));
1099 if (calldata_place == NULL)
1100 MAPS_PRINT_ERROR_CODE_RETURN(MAPS_ERROR_OUT_OF_MEMORY);
1102 calldata_place->callback = callback;
1103 calldata_place->data = user_data;
1105 mapquest_search_req_s *place_req = (mapquest_search_req_s *)g_malloc0(sizeof(mapquest_search_req_s));
1106 if (place_req == NULL) {
1107 g_free(calldata_place);
1108 calldata_place = NULL;
1109 MAPS_PRINT_ERROR_CODE_RETURN(MAPS_ERROR_OUT_OF_MEMORY);
1112 place_req->maps_key = g_strdup((gchar *) __provider_key);
1115 maps_preference_get_max_results(preference, &max_result);
1117 if (max_result == 0)
1118 place_req->num_res = DEFAULT_NUM_RESULTS;
1120 place_req->num_res = max_result;
1122 MAPS_LOGD("Place Result limit :: %d", place_req->num_res);
1124 char *categoryName = NULL;
1125 char *place_name = NULL;
1127 maps_place_category_h category = NULL;
1128 maps_place_filter_get_category(filter, &category);
1131 maps_place_category_get_name(category, &categoryName);
1133 maps_place_filter_get_place_name(filter, &place_name);
1135 char *modified_place_name = NULL;
1136 bool b_isPlaceName_modified = false;
1138 b_isPlaceName_modified = __replace_space(place_name, &modified_place_name);
1140 MAPS_LOGD("Modified Place String.. ");
1141 MAPS_LOGD(" >>>> %s", modified_place_name);
1143 if (categoryName && place_name) {
1144 if (b_isPlaceName_modified)
1145 place_req->search_string = g_strdup_printf("%s[%s]", modified_place_name, categoryName);
1147 place_req->search_string = g_strdup_printf("%s[%s]", place_name, categoryName);
1148 } else if (categoryName) {
1149 place_req->search_string = g_strdup_printf("[%s]", categoryName);
1150 } else if (place_name) {
1151 if (b_isPlaceName_modified)
1152 place_req->search_string = g_strdup_printf("%s", modified_place_name);
1154 place_req->search_string = g_strdup_printf("%s", place_name);
1156 g_free(calldata_place);
1157 calldata_place = NULL;
1160 return MAPS_ERROR_INVALID_PARAMETER;
1163 if (modified_place_name) {
1164 g_free(modified_place_name);
1165 modified_place_name = NULL;
1168 MAPS_LOGD(">>>>>>>> Place search string :: %s <<<<<<<<<", place_req->search_string);
1170 place_req->boundary = NULL;
1171 place_req->boundary = (mapquest_boundary_s *)g_malloc0(sizeof(mapquest_boundary_s));
1173 if (place_req->boundary) {
1174 place_req->boundary->type = MAPQUEST_BOUNDARY_CIRCLE;
1176 maps_coordinates_get_latitude(position, &lat);
1177 maps_coordinates_get_longitude(position, &lon);
1178 place_req->boundary->circle.center.latitude = lat;
1179 place_req->boundary->circle.center.longitude = lon;
1180 place_req->boundary->circle.radius = distance;
1183 *request_id = ++__request_id;
1184 calldata_place->reqID = __request_id;
1186 int ret = mapquest_search_place(place_req, __mapquest_place_search_cb, __request_id, (void *) calldata_place);
1188 return __convert_to_maps_error(ret);
1191 EXPORT_API int maps_plugin_search_place_by_area(const maps_area_h boundary, const maps_place_filter_h filter, const maps_preference_h preference, maps_service_search_place_cb callback, void *user_data, int *request_id)
1193 if (!boundary || !filter || !callback || !request_id)
1194 return MAPS_ERROR_INVALID_PARAMETER;
1196 callback_info_place *calldata_place = (callback_info_place *)g_malloc0(sizeof(callback_info_place));
1197 if (calldata_place == NULL)
1198 MAPS_PRINT_ERROR_CODE_RETURN(MAPS_ERROR_OUT_OF_MEMORY);
1200 calldata_place->callback = callback;
1201 calldata_place->data = user_data;
1203 mapquest_search_req_s *place_req = (mapquest_search_req_s *)g_malloc0(sizeof(mapquest_search_req_s));
1204 if (place_req == NULL) {
1205 g_free(calldata_place);
1206 calldata_place = NULL;
1207 MAPS_PRINT_ERROR_CODE_RETURN(MAPS_ERROR_OUT_OF_MEMORY);
1210 place_req->maps_key = g_strdup((gchar *) __provider_key);
1213 maps_preference_get_max_results(preference, &max_result);
1215 if (max_result == 0)
1216 place_req->num_res = DEFAULT_NUM_RESULTS;
1218 place_req->num_res = max_result;
1220 MAPS_LOGD("Place Result limit :: %d", place_req->num_res);
1222 char *categoryName = NULL;
1223 char *place_name = NULL;
1225 maps_place_category_h category = NULL;
1226 maps_place_filter_get_category(filter, &category);
1229 maps_place_category_get_name(category, &categoryName);
1231 maps_place_filter_get_place_name(filter, &place_name);
1233 char *modified_place_name = NULL;
1234 bool b_isPlaceName_modified = false;
1236 b_isPlaceName_modified = __replace_space(place_name, &modified_place_name);
1238 if (categoryName && place_name) {
1239 if (b_isPlaceName_modified)
1240 place_req->search_string = g_strdup_printf("%s[%s]", modified_place_name, categoryName);
1242 place_req->search_string = g_strdup_printf("%s[%s]", place_name, categoryName);
1243 } else if (categoryName) {
1244 place_req->search_string = g_strdup_printf("[%s]", categoryName);
1245 } else if (place_name) {
1246 if (b_isPlaceName_modified)
1247 place_req->search_string = g_strdup_printf("%s", modified_place_name);
1249 place_req->search_string = g_strdup_printf("%s", place_name);
1251 g_free(calldata_place);
1252 calldata_place = NULL;
1255 return MAPS_ERROR_INVALID_PARAMETER;
1258 if (modified_place_name) {
1259 g_free(modified_place_name);
1260 modified_place_name = NULL;
1263 MAPS_LOGD(">>>>>>>> Place search string :: %s <<<<<<<<<", place_req->search_string);
1264 place_req->boundary = NULL;
1265 maps_area_s *bound = (maps_area_s *) boundary;
1267 if (bound->type != MAPS_AREA_NONE) {
1268 place_req->boundary = (mapquest_boundary_s *)g_malloc0(sizeof(mapquest_boundary_s));
1270 if (place_req->boundary != NULL) {
1271 if (bound->type == MAPS_AREA_CIRCLE) {
1272 place_req->boundary->type = MAPQUEST_BOUNDARY_CIRCLE;
1273 place_req->boundary->circle.center.latitude = bound->circle.center.latitude;
1274 place_req->boundary->circle.center.longitude = bound->circle.center.longitude;
1275 place_req->boundary->circle.radius = bound->circle.radius;
1276 } else if (bound->type == MAPS_AREA_RECTANGLE) {
1277 place_req->boundary->type = MAPQUEST_BOUNDARY_RECT;
1278 place_req->boundary->rect.top_left.latitude = bound->rect.top_left.latitude;
1279 place_req->boundary->rect.top_left.longitude = bound->rect.top_left.longitude;
1280 place_req->boundary->rect.bottom_right.latitude = bound->rect.bottom_right.latitude;
1281 place_req->boundary->rect.bottom_right.longitude = bound->rect.bottom_right.longitude;
1286 *request_id = ++__request_id;
1287 calldata_place->reqID = __request_id;
1289 int ret = mapquest_search_place(place_req, __mapquest_place_search_cb, __request_id, (void *) calldata_place);
1291 return __convert_to_maps_error(ret);
1294 EXPORT_API int maps_plugin_search_place_by_address(const char *address, const maps_area_h boundary, const maps_place_filter_h filter, const maps_preference_h preference, maps_service_search_place_cb callback, void *user_data, int *request_id)
1296 if (!address || !boundary || !filter || !callback || !request_id)
1297 return MAPS_ERROR_INVALID_PARAMETER;
1299 callback_info_place *calldata_place = (callback_info_place *)g_malloc0(sizeof(callback_info_place));
1300 if (calldata_place == NULL)
1301 MAPS_PRINT_ERROR_CODE_RETURN(MAPS_ERROR_OUT_OF_MEMORY);
1303 calldata_place->callback = callback;
1304 calldata_place->data = user_data;
1306 mapquest_search_req_s *place_req = (mapquest_search_req_s *)g_malloc0(sizeof(mapquest_search_req_s));
1307 if (place_req == NULL) {
1308 g_free(calldata_place);
1309 calldata_place = NULL;
1310 MAPS_PRINT_ERROR_CODE_RETURN(MAPS_ERROR_OUT_OF_MEMORY);
1313 place_req->maps_key = g_strdup((gchar *) __provider_key);
1316 maps_preference_get_max_results(preference, &max_result);
1318 if (max_result == 0)
1319 place_req->num_res = DEFAULT_NUM_RESULTS;
1321 place_req->num_res = max_result;
1323 MAPS_LOGD("Place Result limit :: %d", place_req->num_res);
1325 char *categoryName = NULL;
1327 maps_place_category_h category = NULL;
1328 maps_place_filter_get_category(filter, &category);
1331 maps_place_category_get_name(category, &categoryName);
1333 char *modified_address = NULL;
1334 bool b_isAddress_modified = false;
1336 b_isAddress_modified = __replace_space((char *) address, &modified_address);
1339 if (b_isAddress_modified)
1340 place_req->search_string = g_strdup_printf("%s[%s]", modified_address, categoryName);
1342 place_req->search_string = g_strdup_printf("%s[%s]", address, categoryName);
1344 if (b_isAddress_modified)
1345 place_req->search_string = g_strdup_printf("%s", modified_address);
1347 place_req->search_string = g_strdup_printf("%s", address);
1350 if (modified_address) {
1351 g_free(modified_address);
1352 modified_address = NULL;
1355 place_req->boundary = NULL;
1356 maps_area_s *bound = (maps_area_s *) boundary;
1358 if (bound->type != MAPS_AREA_NONE) {
1359 place_req->boundary = (mapquest_boundary_s *)g_malloc0(sizeof(mapquest_boundary_s));
1361 if (place_req->boundary != NULL) {
1362 if (bound->type == MAPS_AREA_CIRCLE) {
1363 place_req->boundary->type = MAPQUEST_BOUNDARY_CIRCLE;
1364 place_req->boundary->circle.center.latitude = bound->circle.center.latitude;
1365 place_req->boundary->circle.center.longitude = bound->circle.center.longitude;
1366 place_req->boundary->circle.radius = bound->circle.radius;
1367 } else if (bound->type == MAPS_AREA_RECTANGLE) {
1368 place_req->boundary->type = MAPQUEST_BOUNDARY_RECT;
1369 place_req->boundary->rect.top_left.latitude = bound->rect.top_left.latitude;
1370 place_req->boundary->rect.top_left.longitude = bound->rect.top_left.longitude;
1371 place_req->boundary->rect.bottom_right.latitude = bound->rect.bottom_right.latitude;
1372 place_req->boundary->rect.bottom_right.longitude = bound->rect.bottom_right.longitude;
1377 *request_id = ++__request_id;
1378 calldata_place->reqID = __request_id;
1380 int ret = mapquest_search_place(place_req, __mapquest_place_search_cb, __request_id, (void *) calldata_place);
1382 return __convert_to_maps_error(ret);
1385 EXPORT_API int maps_plugin_cancel_request(int request_id)
1387 MAPS_LOGD("Plugin_Cancel_Request...");
1389 return MAPS_ERROR_INVALID_PARAMETER;
1391 int ret = mapquest_cancel_request(request_id);
1393 return __convert_to_maps_error(ret);