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.
17 #include "here_place.h"
19 HERE_PLUGIN_BEGIN_NAMESPACE
21 HerePlace::HerePlace(void *pCbFunc, void *pUserData, int nReqId)
23 m_pDiscoveryQuery = NULL;
24 m_pPlaceDetailsQuery = NULL;
27 m_pUserData = pUserData;
35 HerePlace::~HerePlace()
37 if (m_pDiscoveryQuery)
39 delete m_pDiscoveryQuery;
40 m_pDiscoveryQuery = NULL;
43 if (m_pPlaceDetailsQuery)
45 delete m_pPlaceDetailsQuery;
46 m_pPlaceDetailsQuery = NULL;
49 while(!m_PlaceList.empty())
51 maps_place_destroy(m_PlaceList.front());
52 m_PlaceList.pop_front();
56 here_error_e HerePlace::PrepareDiscoveryQuery()
58 if (m_pDiscoveryQuery)
59 return HERE_ERROR_PERMISSION_DENIED;
61 m_pDiscoveryQuery = new DiscoveryQuery();
63 if (!m_pDiscoveryQuery)
64 return HERE_ERROR_OUT_OF_MEMORY;
66 return HERE_ERROR_NONE;
69 here_error_e HerePlace::PrepareDiscoveryPreference(maps_preference_h hPref)
71 if (!m_pDiscoveryQuery)
72 return HERE_ERROR_OUT_OF_MEMORY;
75 return HERE_ERROR_INVALID_PARAMETER;
79 char *szLanguage = NULL;
80 ret = maps_preference_get_language(hPref, &szLanguage);
81 if (ret == MAPS_ERROR_NONE && szLanguage && *szLanguage)
82 m_pDiscoveryQuery->SetLanguage(szLanguage);
86 ret = maps_preference_get_max_results(hPref, &nMaxResults);
87 if (ret == MAPS_ERROR_NONE)
88 m_pDiscoveryQuery->SetMaxResults((size_t)nMaxResults);
91 ret = maps_preference_get(hPref, MAPS_PLACE_FILTER_SORT_BY, &szSortBy);
92 if (ret == MAPS_ERROR_NONE)
93 m_szSortBy = szSortBy;
95 return HERE_ERROR_NONE;
98 here_error_e HerePlace::PrepareDiscoveryFilter(maps_place_filter_h hFilter)
100 if (!m_pDiscoveryQuery)
101 return HERE_ERROR_OUT_OF_MEMORY;
104 return HERE_ERROR_INVALID_PARAMETER;
107 maps_place_category_h mapsCate = NULL;
108 if (maps_place_filter_get_category(hFilter, &mapsCate) == MAPS_ERROR_NONE)
110 CategoryList hereCateList;
112 char *szId = NULL, *szName = NULL, *szUrl = NULL;
114 ret = maps_place_category_get_name(mapsCate, &szName);
115 if (ret == MAPS_ERROR_NONE && szName && *szName)
116 hereCate.SetTitle(szName);
119 ret = maps_place_category_get_url(mapsCate, &szUrl);
120 if (ret == MAPS_ERROR_NONE && szUrl && *szUrl)
121 hereCate.SetHref(szUrl);
124 ret = maps_place_category_get_id(mapsCate, &szId);
125 if (ret == MAPS_ERROR_NONE && szId && *szId)
127 hereCate.SetCategoryId(CategoryId(szId));
128 hereCateList.push_back(hereCate);
129 m_pDiscoveryQuery->SetCategoriesFilter(hereCateList);
133 maps_place_category_destroy(mapsCate);
137 ret = maps_place_filter_get_place_name(hFilter, &szName);
138 if (ret == MAPS_ERROR_NONE && szName && *szName)
139 m_pDiscoveryQuery->SetSearchText(szName);
142 return HERE_ERROR_NONE;
145 here_error_e HerePlace::StartDiscoveryPlace(maps_coordinates_h hCoord, int nDistance)
147 if (!m_pDiscoveryQuery)
148 return HERE_ERROR_OUT_OF_MEMORY;
151 return HERE_ERROR_INVALID_PARAMETER;
154 if (m_pDiscoveryQuery->GetSearchText().empty())
156 m_pDiscoveryQuery->SetType(DiscoveryQuery::QT_EXPLORE);
159 maps_coordinates_get_latitude(hCoord, &dLat);
160 maps_coordinates_get_longitude(hCoord, &dLon);
161 GeoCoordinates geoCoord(dLat, dLon);
165 GeoBoundingCircle geoCircle(geoCoord, nDistance);
166 m_pDiscoveryQuery->SetArea(geoCircle);
168 else if (nDistance == 0)
170 m_pDiscoveryQuery->SetProximity(geoCoord);
173 return HERE_ERROR_INVALID_PARAMETER;
175 m_nRestReqId = m_pDiscoveryQuery->Execute(*this, NULL);
177 return (m_nRestReqId > 0 ? HERE_ERROR_NONE : HERE_ERROR_INVALID_OPERATION);
182 maps_area_h hArea = NULL;
183 maps_area_create_circle(hCoord, nDistance, &hArea);
184 error = StartDiscoveryPlaceByAddress(m_pDiscoveryQuery->GetSearchText().data(), hArea);
185 maps_area_destroy(hArea);
190 here_error_e HerePlace::StartDiscoveryPlaceByArea(maps_area_h hArea)
192 if (!m_pDiscoveryQuery)
193 return HERE_ERROR_OUT_OF_MEMORY;
196 return HERE_ERROR_INVALID_PARAMETER;
199 if (m_pDiscoveryQuery->GetSearchText().empty())
201 m_pDiscoveryQuery->SetType(DiscoveryQuery::QT_EXPLORE);
203 maps_area_s *pArea = (maps_area_s*)hArea;
204 if (pArea->type == MAPS_AREA_RECTANGLE)
206 GeoBoundingBox box(pArea->rect.top_left.longitude, pArea->rect.bottom_right.longitude,
207 pArea->rect.bottom_right.latitude, pArea->rect.top_left.latitude);
208 m_pDiscoveryQuery->SetArea(box);
210 else if (pArea->type == MAPS_AREA_CIRCLE)
212 GeoCoordinates coord(pArea->circle.center.latitude, pArea->circle.center.longitude);
213 GeoBoundingCircle circle(coord, pArea->circle.radius);
214 m_pDiscoveryQuery->SetArea(circle);
217 return HERE_ERROR_INVALID_PARAMETER;
220 m_nRestReqId = m_pDiscoveryQuery->Execute(*this, NULL);
222 return (m_nRestReqId > 0 ? HERE_ERROR_NONE : HERE_ERROR_INVALID_OPERATION);
226 return StartDiscoveryPlaceByAddress(m_pDiscoveryQuery->GetSearchText().data(), hArea);
230 here_error_e HerePlace::StartDiscoveryPlaceByAddress(const char *szAddr, maps_area_h hArea)
232 if (!m_pDiscoveryQuery)
233 return HERE_ERROR_OUT_OF_MEMORY;
235 if (!szAddr || (szAddr && strlen(szAddr) <= 0) || !hArea)
236 return HERE_ERROR_INVALID_PARAMETER;
239 m_pDiscoveryQuery->SetType(DiscoveryQuery::QT_SEARCH);
241 String szSearchText = szAddr;
242 if (m_pDiscoveryQuery->GetSearchText().size())
243 szSearchText += " " + m_pDiscoveryQuery->GetSearchText();
244 m_pDiscoveryQuery->SetSearchText(szSearchText);
246 maps_area_s *pArea = (maps_area_s*)hArea;
247 if (pArea->type == MAPS_AREA_RECTANGLE)
249 double dLat1 = pArea->rect.top_left.latitude;
250 double dLng1 = pArea->rect.top_left.longitude;
251 double dLat2 = pArea->rect.bottom_right.latitude;
252 double dLng2 = pArea->rect.bottom_right.longitude;
253 double dLat = (dLat1 + dLat2) / 2;
254 double dLng = (dLng1 + dLng2) / 2;
256 GeoCoordinates geoCoord(dLat, dLng);
257 m_pDiscoveryQuery->SetProximity(geoCoord);
259 else if(pArea->type == MAPS_AREA_CIRCLE)
261 double dLat = pArea->circle.center.latitude;
262 double dLng = pArea->circle.center.longitude;
263 GeoCoordinates geoCoord(dLat, dLng);
264 m_pDiscoveryQuery->SetProximity(geoCoord);
268 m_nRestReqId = m_pDiscoveryQuery->Execute(*this, NULL);
270 return (m_nRestReqId > 0 ? HERE_ERROR_NONE : HERE_ERROR_INVALID_OPERATION);
273 here_error_e HerePlace::PreparePlaceDetailsQuery()
275 if (m_pPlaceDetailsQuery)
276 return HERE_ERROR_PERMISSION_DENIED;
278 m_pPlaceDetailsQuery = new PlaceDetailsQuery();
280 if (!m_pPlaceDetailsQuery)
281 return HERE_ERROR_OUT_OF_MEMORY;
283 return HERE_ERROR_NONE;
286 here_error_e HerePlace::PreparePlaceDetailsPreference(maps_preference_h hPref)
288 if (!m_pPlaceDetailsQuery)
289 return HERE_ERROR_OUT_OF_MEMORY;
292 return HERE_ERROR_INVALID_PARAMETER;
295 char *szLanguage = NULL;
296 ret = maps_preference_get_language(hPref, &szLanguage);
297 if (ret == MAPS_ERROR_NONE && szLanguage && *szLanguage)
298 m_pPlaceDetailsQuery->SetLanguage(szLanguage);
301 return HERE_ERROR_NONE;
304 here_error_e HerePlace::StartPlaceDetails(const char *szPlaceId)
306 if (!m_pPlaceDetailsQuery)
307 return HERE_ERROR_OUT_OF_MEMORY;
309 if (!szPlaceId || (szPlaceId && strlen(szPlaceId) <= 0))
310 return HERE_ERROR_INVALID_PARAMETER;
313 m_pPlaceDetailsQuery->SetPlaceId(szPlaceId);
316 m_nRestReqId = m_pPlaceDetailsQuery->Execute(*this, NULL);
318 return (m_nRestReqId > 0 ? HERE_ERROR_NONE : HERE_ERROR_INVALID_OPERATION);
321 here_error_e HerePlace::StartPlaceDetailsInternal(const char *szUrl)
323 if (!szUrl || (szUrl && strlen(szUrl) <= 0))
324 return HERE_ERROR_INVALID_PARAMETER;
327 std::unique_ptr<PlaceDetailsQuery> pPlaceDetailsQuery (new (std::nothrow)PlaceDetailsQuery());
330 bool bExcuted = (int)(pPlaceDetailsQuery->Execute(*this, NULL, szUrl) > 0);
332 return (bExcuted ? HERE_ERROR_NONE : HERE_ERROR_INVALID_OPERATION);
335 void HerePlace::OnDiscoverReply (const DiscoveryReply &Reply)
337 if (m_bCanceled) /* ignore call back if it was cancelled. */
343 maps_place_h mapsPlace;
344 PlaceItemList herePlaceList = Reply.GetPlaceItems();
345 PlaceItemList::iterator herePlaceIt;
346 SearchItemList hereSearchList = Reply.GetSearchItems();
347 SearchItemList::iterator hereSearchIt;
348 LinkObject hereLinkObj;
349 GeoCoordinates hereCoord;
350 maps_coordinates_h mapsCoord;
352 maps_place_category_h mapsCate;
353 maps_place_rating_h mapsRating;
354 int error = MAPS_ERROR_UNKNOWN, sub_error;
355 bool is_valid, isPending;
359 m_nReplyCnt = herePlaceList.size() + hereSearchList.size();
361 if (m_nReplyCnt == 0)
363 ((maps_service_search_place_cb)m_pCbFunc)(MAPS_ERROR_NOT_FOUND, m_nReqId,
364 0, 1, NULL, m_pUserData);
369 for (herePlaceIt = herePlaceList.begin();
370 herePlaceIt != herePlaceList.end() && !m_bCanceled;
375 if ((error = maps_place_create(&mapsPlace)) == MAPS_ERROR_NONE)
378 hereLinkObj = herePlaceIt->GetLinkObject();
380 if (!hereLinkObj.GetTitle().empty())
381 maps_place_set_name(mapsPlace, (char*)hereLinkObj.GetTitle().c_str());
383 if (!hereLinkObj.GetHref().empty())
384 maps_place_set_uri(mapsPlace, (char*)hereLinkObj.GetHref().c_str());
386 if (!hereLinkObj.GetId().empty())
387 maps_place_set_id(mapsPlace, (char*)hereLinkObj.GetId().c_str());
393 hereCoord = herePlaceIt->GetPosition();
394 if (maps_coordinates_create(hereCoord.GetLatitude(), hereCoord.GetLongitude(),
395 &mapsCoord) == MAPS_ERROR_NONE)
397 maps_place_set_location(mapsPlace, mapsCoord);
398 maps_coordinates_destroy(mapsCoord);
401 /* rating (optional) */
402 if (maps_place_rating_create(&mapsRating) == MAPS_ERROR_NONE)
404 maps_place_rating_set_average(mapsRating, herePlaceIt->GetAverageRating());
405 maps_place_set_rating(mapsPlace, mapsRating);
406 maps_place_rating_destroy(mapsRating);
409 /* category (optional) */
410 hereCate = herePlaceIt->GetCategory();
412 maps_item_list_h mapsCateList;
413 if (maps_item_list_create(&mapsCateList) == MAPS_ERROR_NONE)
415 if (maps_place_category_create(&mapsCate) == MAPS_ERROR_NONE)
419 if (!hereCate.GetCategoryId().ToString().empty())
421 sub_error = maps_place_category_set_id(mapsCate,
422 (char*)hereCate.GetCategoryId().ToString().c_str());
423 is_valid |= (sub_error == MAPS_ERROR_NONE);
426 if (!hereCate.GetTitle().empty())
428 sub_error = maps_place_category_set_name(mapsCate,
429 (char*)hereCate.GetTitle().c_str());
430 is_valid |= (sub_error == MAPS_ERROR_NONE);
433 if (!hereCate.GetHref().empty())
435 sub_error = maps_place_category_set_url(mapsCate,
436 (char*)hereCate.GetHref().c_str());
437 is_valid |= (sub_error == MAPS_ERROR_NONE);
442 maps_item_list_append(mapsCateList, mapsCate, maps_place_category_clone);
443 maps_place_set_categories(mapsPlace, mapsCateList);
444 maps_item_list_remove_all(mapsCateList, maps_place_category_destroy);
446 maps_place_category_destroy(mapsCate);
448 maps_item_list_destroy(mapsCateList);
452 maps_place_set_distance(mapsPlace, (int)herePlaceIt->GetDistance());
455 /* herePlaceList.GetIsSponsored() */
459 /* If needed PlaceDetails information, postpone to send a reply */
460 if(__sending_place_details_query_automatically)
462 hereLinkObj = herePlaceIt->GetLinkObject();
463 if (!hereLinkObj.GetHref().empty() && !hereLinkObj.GetId().empty())
465 m_PlaceList.push_back(mapsPlace);
467 StartPlaceDetailsInternal(hereLinkObj.GetHref().c_str());
468 MAPS_LOGD("Add maps_place_h to the pending list. id=%s", hereLinkObj.GetId().data());
475 m_PlaceList.push_back(mapsPlace);
479 for (hereSearchIt = hereSearchList.begin();
480 hereSearchIt != hereSearchList.end() && !m_bCanceled;
483 error = maps_place_create(&mapsPlace);
485 if(error == MAPS_ERROR_NONE)
490 hereLinkObj = hereSearchIt->GetLinkObject();
492 if (!hereLinkObj.GetTitle().empty())
494 sub_error = maps_place_set_name(mapsPlace,
495 (char*)hereLinkObj.GetTitle().c_str());
496 is_valid |= (sub_error == MAPS_ERROR_NONE);
499 if (!hereLinkObj.GetHref().empty())
501 sub_error = maps_place_set_uri(mapsPlace,
502 (char*)hereLinkObj.GetHref().c_str());
503 is_valid |= (sub_error == MAPS_ERROR_NONE);
506 if (!hereLinkObj.GetId().empty())
508 sub_error = maps_place_set_id(mapsPlace,
509 (char*)hereLinkObj.GetId().c_str());
510 is_valid |= (sub_error == MAPS_ERROR_NONE);
516 error = MAPS_ERROR_NOT_FOUND;
519 m_PlaceList.push_back(mapsPlace);
524 if (m_nReplyIdx == m_nReplyCnt - 1)
526 __sortList(m_PlaceList);
529 while (m_nReplyIdx < m_nReplyCnt && !m_bCanceled && !m_PlaceList.empty())
531 mapsPlace = m_PlaceList.front();
532 m_PlaceList.pop_front();
534 /* callback function */
535 if (((maps_service_search_place_cb)m_pCbFunc)((maps_error_e)error, m_nReqId,
536 m_nReplyIdx++, m_nReplyCnt, mapsPlace, m_pUserData) == FALSE)
545 void HerePlace::OnPlaceDetailsReply (const PlaceDetailsReply &Reply)
547 if (m_bCanceled) /* ignore call back if it was cancelled. */
553 if (m_nReplyCnt == 0)
556 PlaceDetails herePlace = Reply.GetPlaceDetails();
557 maps_place_h mapsPlace = NULL;
558 int error = MAPS_ERROR_NONE, sub_error;
559 bool is_valid, isPending = false;
563 /* Finding maps_place_h which is already pending since DiscoverReply */
564 PlaceList::iterator it;
565 for (it = m_PlaceList.begin(); it != m_PlaceList.end(); it++)
567 if (maps_place_get_id(*it, &placeId) == MAPS_ERROR_NONE)
569 placeIdLen = strlen(placeId);
570 if(!herePlace.GetPlaceId().compare(0, placeIdLen, placeId))
575 MAPS_LOGD("Found maps_place_h (%p) which is pending since DiscoveryReply", mapsPlace);
582 /* If not found, create new handle */
584 error = maps_place_create(&mapsPlace);
586 if (error == MAPS_ERROR_NONE)
591 if (!herePlace.GetName().empty())
593 sub_error = maps_place_set_name(mapsPlace, (char*)herePlace.GetName().c_str());
594 is_valid |= (sub_error == MAPS_ERROR_NONE);
598 if (!herePlace.GetPlaceId().empty())
600 sub_error = maps_place_set_id(mapsPlace, (char*)herePlace.GetPlaceId().c_str());
601 is_valid |= (sub_error == MAPS_ERROR_NONE);
605 if (!herePlace.GetView().empty())
607 sub_error = maps_place_set_uri(mapsPlace, (char*)herePlace.GetView().c_str());
608 is_valid |= (sub_error == MAPS_ERROR_NONE);
614 /* maps not supported // herePlace.GetIconPath(); */
617 ProcessPlaceLocation(herePlace, mapsPlace);
619 ProcessPlaceContact(herePlace, mapsPlace);
621 ProcessPlaceCategory(herePlace, mapsPlace);
624 /* maps & here not supported */
626 ProcessPlaceImage(herePlace, mapsPlace);
628 ProcessPlaceDetails(herePlace, mapsPlace);
630 ProcessPlaceReviews(herePlace, mapsPlace);
632 ProcessPlaceRatings(herePlace, mapsPlace);
634 ProcessPlaceRated(herePlace, mapsPlace);
638 error = MAPS_ERROR_NOT_FOUND;
643 m_PlaceList.push_back(mapsPlace);
648 if (m_nReplyIdx == m_nReplyCnt - 1)
650 __sortList(m_PlaceList);
653 while (m_nReplyIdx < m_nReplyCnt && !m_bCanceled && !m_PlaceList.empty())
655 mapsPlace = m_PlaceList.front();
656 m_PlaceList.pop_front();
658 /* callback function */
659 if (((maps_service_search_place_cb)m_pCbFunc)((maps_error_e)error, m_nReqId,
660 m_nReplyIdx++, m_nReplyCnt, mapsPlace, m_pUserData) == FALSE)
669 void HerePlace::ProcessPlaceLocation(PlaceDetails herePlace, maps_place_h mapsPlace)
671 GeoLocation hereLocation = herePlace.GetLocation();
674 GeoCoordinates hereCoord = hereLocation.GetDisplayPosition();
675 maps_coordinates_h mapsCoord;
677 if (maps_coordinates_create(hereCoord.GetLatitude(),
678 hereCoord.GetLongitude(), &mapsCoord) == MAPS_ERROR_NONE)
680 maps_place_set_location(mapsPlace, mapsCoord);
681 maps_coordinates_destroy(mapsCoord);
685 Address hereAddr = hereLocation.GetAddress();
686 maps_address_h mapsAddr;
690 if (maps_address_create(&mapsAddr) == MAPS_ERROR_NONE)
694 if (!hereAddr.GetHouseNumber().empty())
696 error = maps_address_set_building_number(mapsAddr,
697 hereAddr.GetHouseNumber().c_str());
698 is_valid |= (error == MAPS_ERROR_NONE);
701 if (!hereAddr.GetStreet().empty())
703 error = maps_address_set_street(mapsAddr, hereAddr.GetStreet().c_str());
704 is_valid |= (error == MAPS_ERROR_NONE);
707 if (!hereAddr.GetDistrict().empty())
709 error = maps_address_set_district(mapsAddr, hereAddr.GetDistrict().c_str());
710 is_valid |= (error == MAPS_ERROR_NONE);
713 if (!hereAddr.GetCity().empty())
715 error = maps_address_set_city(mapsAddr, hereAddr.GetCity().c_str());
716 is_valid |= (error == MAPS_ERROR_NONE);
719 if (!hereAddr.GetState().empty())
721 error = maps_address_set_state(mapsAddr, hereAddr.GetState().c_str());
722 is_valid |= (error == MAPS_ERROR_NONE);
725 if (!hereAddr.GetCountry().empty())
727 error = maps_address_set_country(mapsAddr, hereAddr.GetCountry().c_str());
728 is_valid |= (error == MAPS_ERROR_NONE);
731 if (!hereAddr.GetCountryCode().empty())
733 error = maps_address_set_country_code(mapsAddr, hereAddr.GetCountryCode().c_str());
734 is_valid |= (error == MAPS_ERROR_NONE);
737 if (!hereAddr.GetCounty().empty())
739 error = maps_address_set_county(mapsAddr, hereAddr.GetCounty().c_str());
740 is_valid |= (error == MAPS_ERROR_NONE);
743 if (!hereAddr.GetPostalCode().empty())
745 error = maps_address_set_postal_code(mapsAddr, hereAddr.GetPostalCode().c_str());
746 is_valid |= (error == MAPS_ERROR_NONE);
749 if (!hereAddr.GetLabel().empty())
751 error = maps_address_set_freetext(mapsAddr, hereAddr.GetLabel().c_str());
752 is_valid |= (error == MAPS_ERROR_NONE);
757 maps_place_set_address(mapsPlace, mapsAddr);
759 maps_address_destroy(mapsAddr);
764 void HerePlace::ProcessPlaceContact(PlaceDetails herePlace, maps_place_h mapsPlace)
767 ContactDetailsList hereContList = herePlace.GetContactDetails();
768 ContactDetailsList::iterator hereCont;
769 maps_item_list_h mapsContList;
770 maps_place_contact_h mapsCont;
774 if (hereContList.empty()) return;
776 if (maps_item_list_create(&mapsContList) != MAPS_ERROR_NONE) return;
778 for (hereCont = hereContList.begin(); hereCont != hereContList.end(); hereCont++)
780 if (maps_place_contact_create(&mapsCont) != MAPS_ERROR_NONE) continue;
784 if (!hereCont->GetLabel().empty())
786 error = maps_place_contact_set_label(mapsCont,
787 (char*)hereCont->GetLabel().c_str());
788 is_valid |= (error == MAPS_ERROR_NONE);
791 if (!hereCont->GetValue().empty())
793 error = maps_place_contact_set_value(mapsCont,
794 (char*)hereCont->GetValue().c_str());
795 is_valid |= (error == MAPS_ERROR_NONE);
798 if (!hereCont->GetContactType().empty())
800 error = maps_place_contact_set_type(mapsCont,
801 (char*)hereCont->GetContactType().c_str());
802 is_valid |= (error == MAPS_ERROR_NONE);
807 maps_item_list_append(mapsContList, mapsCont,
808 maps_place_contact_clone);
810 maps_place_contact_destroy(mapsCont);
813 if (maps_item_list_items(mapsContList))
815 maps_place_set_contacts(mapsPlace, mapsContList);
816 maps_item_list_remove_all(mapsContList, maps_place_contact_destroy);
818 maps_item_list_destroy(mapsContList);
821 void HerePlace::ProcessPlaceCategory(PlaceDetails herePlace, maps_place_h mapsPlace)
823 CategoryList hereCateList = herePlace.GetCategories();
824 CategoryList::iterator hereCate;
825 maps_item_list_h mapsCateList;
826 maps_place_category_h mapsCate;
828 bool is_valid = false;
830 if (hereCateList.empty()) return;
832 if (maps_item_list_create(&mapsCateList) != MAPS_ERROR_NONE) return;
834 // maps-service supports only one category
835 hereCate = hereCateList.begin();
836 if (maps_place_category_create(&mapsCate) == MAPS_ERROR_NONE)
838 if (!hereCate->GetCategoryId().ToString().empty())
840 error = maps_place_category_set_id(mapsCate,
841 hereCate->GetCategoryId().ToString().c_str());
842 is_valid |= (error == MAPS_ERROR_NONE);
845 if (!hereCate->GetTitle().empty())
847 error = maps_place_category_set_name(mapsCate,
848 hereCate->GetTitle().c_str());
849 is_valid |= (error == MAPS_ERROR_NONE);
852 if (!hereCate->GetHref().empty())
854 error = maps_place_category_set_url(mapsCate,
855 hereCate->GetHref().c_str());
856 is_valid |= (error == MAPS_ERROR_NONE);
861 maps_item_list_append(mapsCateList, mapsCate, maps_place_category_clone);
863 maps_place_category_destroy(mapsCate);
866 if (maps_item_list_items(mapsCateList))
868 maps_place_set_categories(mapsPlace, mapsCateList);
869 maps_item_list_remove_all(mapsCateList, maps_place_category_destroy);
871 maps_item_list_destroy(mapsCateList);
874 void HerePlace::ProcessPlaceImage(PlaceDetails herePlace, maps_place_h mapsPlace)
876 ImageContentList hereImageList = herePlace.GetImageContent();
877 ImageContentList::iterator hereImage;
878 maps_item_list_h mapsImageList;
879 maps_place_image_h mapsImage;
880 maps_place_link_object_h mapsImageUser;
881 LinkObject hereImageUser;
883 bool is_valid, is_valid2;
885 if (hereImageList.empty()) return;
887 if (maps_item_list_create(&mapsImageList) != MAPS_ERROR_NONE) return;
889 for (hereImage = hereImageList.begin(); hereImage != hereImageList.end(); hereImage++)
891 if (maps_place_image_create(&mapsImage) != MAPS_ERROR_NONE) continue;
895 /* here not supported
896 // maps_place_image_set_height(maps_place_image_h mapsPlace, const int height); */
898 /* here not supported
899 // maps_place_image_set_media(maps_place_image_h mapsPlace, maps_place_media_h media); */
901 if (!hereImage->GetSource().empty())
903 error = maps_place_image_set_url(mapsImage, (char*)hereImage->GetSource().c_str());
904 is_valid |= (error == MAPS_ERROR_NONE);
907 if (!hereImage->GetImageId().empty())
909 error = maps_place_image_set_id(mapsImage, (char*)hereImage->GetImageId().c_str());
910 is_valid |= (error == MAPS_ERROR_NONE);
913 hereImageUser = hereImage->GetUser();
914 if (maps_place_link_object_create(&mapsImageUser) == MAPS_ERROR_NONE)
918 if (!hereImageUser.GetId().empty())
920 error = maps_place_link_object_set_id(mapsImageUser,
921 (char*)hereImageUser.GetId().c_str());
922 is_valid2 |= (error == MAPS_ERROR_NONE);
925 if (!hereImageUser.GetTitle().empty())
927 error = maps_place_link_object_set_name(mapsImageUser,
928 (char*)hereImageUser.GetTitle().c_str());
929 is_valid2 |= (error == MAPS_ERROR_NONE);
932 if (!hereImageUser.GetHref().empty())
934 error = maps_place_link_object_set_string(mapsImageUser,
935 (char*)hereImageUser.GetHref().c_str());
936 is_valid2 |= (error == MAPS_ERROR_NONE);
939 if (!hereImageUser.GetType().empty())
941 error = maps_place_link_object_set_type(mapsImageUser,
942 (char*)hereImageUser.GetType().c_str());
943 is_valid2 |= (error == MAPS_ERROR_NONE);
948 maps_place_image_set_user_link(mapsImage, mapsImageUser);
949 is_valid |= is_valid2;
951 maps_place_link_object_destroy(mapsImageUser);
956 maps_item_list_append(mapsImageList, mapsImage, maps_place_image_clone);
958 maps_place_image_destroy(mapsImage);
961 if (maps_item_list_items(mapsImageList))
963 maps_place_set_images(mapsPlace, mapsImageList);
964 maps_item_list_remove_all(mapsImageList, maps_place_image_destroy);
966 maps_item_list_destroy(mapsImageList);
969 void HerePlace::ProcessPlaceDetails(PlaceDetails herePlace, maps_place_h mapsPlace)
971 EditorialContentList hereEditList = herePlace.GetEditorialContent();
972 EditorialContentList::iterator hereEdit;
973 maps_item_list_h mapsEditList;
974 maps_place_editorial_h mapsEdit;
978 if (hereEditList.empty()) return;
980 if (maps_item_list_create(&mapsEditList) != MAPS_ERROR_NONE) return;
982 for (hereEdit = hereEditList.begin(); hereEdit != hereEditList.end(); hereEdit++)
984 if (maps_place_editorial_create(&mapsEdit) != MAPS_ERROR_NONE) continue;
988 if (!hereEdit->GetDescription().empty())
990 error = maps_place_editorial_set_description(mapsEdit,
991 (char*)hereEdit->GetDescription().c_str());
992 is_valid |= (error == MAPS_ERROR_NONE);
995 if (!hereEdit->GetLanguage().empty())
997 error = maps_place_editorial_set_language(mapsEdit,
998 (char*)hereEdit->GetLanguage().c_str());
999 is_valid |= (error == MAPS_ERROR_NONE);
1002 /* maps_place_editorial_set_media(mapsEdit, maps_place_media_h media); */
1006 maps_item_list_append(mapsEditList, mapsEdit, maps_place_editorial_clone);
1008 maps_place_editorial_destroy(mapsEdit);
1011 if (maps_item_list_items(mapsEditList))
1013 maps_place_set_editorials(mapsPlace, mapsEditList);
1014 maps_item_list_remove_all(mapsEditList, maps_place_editorial_destroy);
1016 maps_item_list_destroy(mapsEditList);
1019 void HerePlace::ProcessPlaceReviews(PlaceDetails herePlace, maps_place_h mapsPlace)
1021 ReviewContentList hereReviewList = herePlace.GetReviewContent();
1022 ReviewContentList::iterator hereReview;
1023 maps_place_review_h mapsReview;
1024 maps_item_list_h mapsReviewList;
1025 LinkObject hereReviewUser;
1026 maps_place_link_object_h mapsReviewUser;
1028 bool is_valid, is_valid2;
1030 if (hereReviewList.empty()) return;
1032 if (maps_item_list_create(&mapsReviewList) != MAPS_ERROR_NONE) return;
1034 for (hereReview = hereReviewList.begin(); hereReview != hereReviewList.end(); hereReview++)
1036 if (maps_place_review_create(&mapsReview) != MAPS_ERROR_NONE) continue;
1040 if (!hereReview->GetDateTime().empty())
1042 error = maps_place_review_set_date(mapsReview,
1043 (char*)hereReview->GetDateTime().c_str());
1044 is_valid |= (error == MAPS_ERROR_NONE);
1047 if (!hereReview->GetDescription().empty())
1049 error = maps_place_review_set_description(mapsReview,
1050 (char*)hereReview->GetDescription().c_str());
1051 is_valid |= (error == MAPS_ERROR_NONE);
1054 if (!hereReview->GetLanguage().empty())
1056 error = maps_place_review_set_language(mapsReview,
1057 (char*)hereReview->GetLanguage().c_str());
1058 is_valid |= (error == MAPS_ERROR_NONE);
1061 /* maps_place_review_set_media(mapsReview, maps_place_media_h media) */
1063 maps_place_review_set_rating(mapsReview, hereReview->GetRating());
1065 if (!hereReview->GetTitle().empty())
1067 error = maps_place_review_set_title(mapsReview,
1068 (char*)hereReview->GetTitle().c_str());
1069 is_valid |= (error == MAPS_ERROR_NONE);
1072 hereReviewUser = hereReview->GetUser();
1073 if (maps_place_link_object_create(&mapsReviewUser) == MAPS_ERROR_NONE)
1077 if (!hereReviewUser.GetId().empty())
1079 error = maps_place_link_object_set_id(mapsReviewUser,
1080 (char*)hereReviewUser.GetId().c_str());
1081 is_valid2 |= (error == MAPS_ERROR_NONE);
1084 if (!hereReviewUser.GetTitle().empty())
1086 error = maps_place_link_object_set_name(mapsReviewUser,
1087 (char*)hereReviewUser.GetTitle().c_str());
1088 is_valid2 |= (error == MAPS_ERROR_NONE);
1091 if (!hereReviewUser.GetHref().empty())
1093 error = maps_place_link_object_set_string(mapsReviewUser,
1094 (char*)hereReviewUser.GetHref().c_str());
1095 is_valid2 |= (error == MAPS_ERROR_NONE);
1098 if (!hereReviewUser.GetType().empty())
1100 error = maps_place_link_object_set_type(mapsReviewUser,
1101 (char*)hereReviewUser.GetType().c_str());
1102 is_valid2 |= (error == MAPS_ERROR_NONE);
1107 maps_place_review_set_user_link(mapsReview, mapsReviewUser);
1108 is_valid |= is_valid2;
1110 maps_place_link_object_destroy(mapsReviewUser);
1115 maps_item_list_append(mapsReviewList, mapsReview, maps_place_review_clone);
1117 maps_place_review_destroy(mapsReview);
1120 if (maps_item_list_items(mapsReviewList))
1122 maps_place_set_reviews(mapsPlace, mapsReviewList);
1123 maps_item_list_remove_all(mapsReviewList, maps_place_review_destroy);
1125 maps_item_list_destroy(mapsReviewList);
1128 void HerePlace::ProcessPlaceRatings(PlaceDetails herePlace, maps_place_h mapsPlace)
1130 Ratings hereRating = herePlace.GetRatings();
1131 maps_place_rating_h mapsRating;
1133 if (maps_place_rating_create(&mapsRating) != MAPS_ERROR_NONE) return;
1135 maps_place_rating_set_average(mapsRating, hereRating.GetAverage());
1136 maps_place_rating_set_count(mapsRating, hereRating.GetCount());
1137 maps_place_set_rating(mapsPlace, mapsRating);
1138 maps_place_rating_destroy(mapsRating);
1141 void HerePlace::ProcessPlaceRated(PlaceDetails herePlace, maps_place_h mapsPlace)
1143 RelatedItem hereRelated = herePlace.GetRelatedItem();
1144 maps_place_link_object_h mapsRelated;
1146 bool is_valid = false;
1148 if (maps_place_link_object_create(&mapsRelated) != MAPS_ERROR_NONE) return;
1150 //need to check if GetId() exist
1151 //maps_place_link_object_set_id(mapsRelated, hereRelated.GetId());
1153 if (!hereRelated.GetTitle().empty())
1155 error = maps_place_link_object_set_name(mapsRelated,
1156 (char*)hereRelated.GetTitle().c_str());
1157 is_valid |= (error == MAPS_ERROR_NONE);
1160 if (!hereRelated.GetHref().empty())
1162 error = maps_place_link_object_set_string(mapsRelated,
1163 (char*)hereRelated.GetHref().c_str());
1164 is_valid |= (error == MAPS_ERROR_NONE);
1167 if (!hereRelated.GetType().empty())
1169 error = maps_place_link_object_set_type(mapsRelated,
1170 (char*)hereRelated.GetType().c_str());
1171 is_valid |= (error == MAPS_ERROR_NONE);
1176 maps_place_set_related_link(mapsPlace, mapsRelated);
1178 maps_place_link_object_destroy(mapsRelated);
1181 bool HerePlace::__compareWithTitle(const maps_place_h &item1, const maps_place_h &item2)
1183 bool result = false;
1184 char *str1 = NULL, *str2 = NULL;
1186 if (maps_place_get_name(item1, &str1) == MAPS_ERROR_NONE &&
1187 maps_place_get_name(item2, &str2) == MAPS_ERROR_NONE)
1189 result = (strcmp(str1, str2) < 0);
1196 bool HerePlace::__compareWithId(const maps_place_h &item1, const maps_place_h &item2)
1198 bool result = false;
1199 char *str1 = NULL, *str2 = NULL;
1201 if (maps_place_get_id(item1, &str1) == MAPS_ERROR_NONE &&
1202 maps_place_get_id(item2, &str2) == MAPS_ERROR_NONE)
1204 result = (strcmp(str1, str2) < 0);
1211 bool HerePlace::__compareWithDistance(const maps_place_h &item1, const maps_place_h &item2)
1213 bool result = false;
1214 int num1 = 0, num2 = 0;
1216 if (maps_place_get_distance(item1, &num1) == MAPS_ERROR_NONE &&
1217 maps_place_get_distance(item2, &num2) == MAPS_ERROR_NONE)
1219 result = (num1 < num2);
1224 bool HerePlace::__compareWithRating(const maps_place_h &item1, const maps_place_h &item2)
1226 bool result = false;
1227 maps_place_rating_h rat1 = NULL, rat2 = NULL;
1228 double num1 = 0, num2 = 0;
1230 if (maps_place_get_rating(item1, &rat1) == MAPS_ERROR_NONE &&
1231 maps_place_get_rating(item2, &rat2) == MAPS_ERROR_NONE)
1233 if (maps_place_rating_get_average(rat1, &num1) == MAPS_ERROR_NONE &&
1234 maps_place_rating_get_average(rat2, &num2) == MAPS_ERROR_NONE)
1236 result = (num1 > num2);
1239 maps_place_rating_destroy(rat1);
1240 maps_place_rating_destroy(rat2);
1244 bool HerePlace::__compareWithCategoryCb(int index, int total,
1245 maps_place_category_h category,
1248 user_data = category;
1252 bool HerePlace::__compareWithCategory(const maps_place_h &item1, const maps_place_h &item2)
1254 bool result = false;
1255 maps_place_category_h cat1 = NULL, cat2 = NULL;
1256 char *str1 = NULL, *str2 = NULL;
1258 maps_place_foreach_category(item1, __compareWithCategoryCb, &cat1);
1259 maps_place_foreach_category(item2, __compareWithCategoryCb, &cat2);
1261 if (maps_place_category_get_id(item1, &str1) == MAPS_ERROR_NONE &&
1262 maps_place_category_get_id(item2, &str2) == MAPS_ERROR_NONE)
1264 result = (strcmp(str1, str2) < 0);
1266 maps_place_category_destroy(item1);
1267 maps_place_category_destroy(item2);
1273 void HerePlace::__sortList(PlaceList &list)
1275 if (!m_szSortBy) return;
1277 if (!strcmp(m_szSortBy, "name") || !strcmp(m_szSortBy, "title"))
1279 std::sort(list.begin(), list.end(), __compareWithTitle);
1281 else if (!strcmp(m_szSortBy, "id"))
1283 std::sort(list.begin(), list.end(), __compareWithId);
1285 else if (!strcmp(m_szSortBy, "distance"))
1287 std::sort(list.begin(), list.end(), __compareWithDistance);
1289 else if (!strcmp(m_szSortBy, "rate") || !strcmp(m_szSortBy, "rating"))
1291 std::sort(list.begin(), list.end(), __compareWithRating);
1293 else if (!strcmp(m_szSortBy, "category"))
1295 std::sort(list.begin(), list.end(), __compareWithCategory);
1299 HERE_PLUGIN_END_NAMESPACE