summaryrefslogtreecommitdiff
path: root/src/here/here_place.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/here/here_place.cpp')
-rwxr-xr-xsrc/here/here_place.cpp237
1 files changed, 135 insertions, 102 deletions
diff --git a/src/here/here_place.cpp b/src/here/here_place.cpp
index b42cb5f..e0b859f 100755
--- a/src/here/here_place.cpp
+++ b/src/here/here_place.cpp
@@ -32,6 +32,7 @@ HerePlace::HerePlace(void *pCbFunc, void *pUserData, int nReqId)
m_bReplyFlushed = false;
m_szSortBy = NULL;
m_bPlaceDetailsInternal = false;
+ m_eDistanceUnit = MAPS_DISTANCE_UNIT_M;
}
HerePlace::~HerePlace()
@@ -74,7 +75,7 @@ here_error_e HerePlace::PrepareDiscoveryPreference(maps_preference_h hPref)
return HERE_ERROR_OUT_OF_MEMORY;
if (!hPref)
- return HERE_ERROR_INVALID_PARAMETER;
+ return HERE_ERROR_NONE;
int ret;
@@ -89,6 +90,11 @@ here_error_e HerePlace::PrepareDiscoveryPreference(maps_preference_h hPref)
if (ret == MAPS_ERROR_NONE)
m_pDiscoveryQuery->SetMaxResults((size_t)nMaxResults);
+ maps_distance_unit_e eUnit;
+ ret = maps_preference_get_distance_unit(hPref, &eUnit);
+ if (ret == MAPS_ERROR_NONE)
+ m_eDistanceUnit = eUnit;
+
char *szSortBy;
ret = maps_preference_get(hPref, MAPS_PLACE_FILTER_SORT_BY, &szSortBy);
if (ret == MAPS_ERROR_NONE)
@@ -125,13 +131,16 @@ here_error_e HerePlace::PrepareDiscoveryFilter(maps_place_filter_h hFilter)
ret = maps_place_category_get_id(mapsCate, &szId);
if (ret == MAPS_ERROR_NONE && szId && *szId)
- {
hereCate.SetCategoryId(CategoryId(szId));
- hereCateList.push_back(hereCate);
- m_pDiscoveryQuery->SetCategoriesFilter(hereCateList);
+ else if (hereCate.GetTitle().size() > 0)
+ {
+ hereCate.SetCategoryId(CategoryId(hereCate.GetTitle()));
+ hereCate.SetTitle("");
}
g_free(szId);
+ hereCateList.push_back(hereCate);
+ m_pDiscoveryQuery->SetCategoriesFilter(hereCateList);
maps_place_category_destroy(mapsCate);
}
@@ -141,135 +150,144 @@ here_error_e HerePlace::PrepareDiscoveryFilter(maps_place_filter_h hFilter)
m_pDiscoveryQuery->SetSearchText(szName);
g_free(szName);
+ char *szKeyword = NULL;
+ ret = maps_place_filter_get_keyword(hFilter, &szKeyword);
+ if (ret == MAPS_ERROR_NONE && szKeyword && *szKeyword)
+ {
+ String szSearchText = m_pDiscoveryQuery->GetSearchText();
+ if (szSearchText.size() > 0) szSearchText += " ";
+ szSearchText += szKeyword;
+ m_pDiscoveryQuery->SetSearchText(szSearchText);
+ }
+ g_free(szKeyword);
+
return HERE_ERROR_NONE;
}
here_error_e HerePlace::StartDiscoveryPlace(maps_coordinates_h hCoord, int nDistance)
{
+ if (!hCoord || nDistance < 0)
+ return HERE_ERROR_INVALID_PARAMETER;
+
+ int meters = (int)(HereUtils::ConvertDistance(nDistance, m_eDistanceUnit, MAPS_DISTANCE_UNIT_M) + 0.5);
+ maps_area_h area = NULL;
+ maps_area_create_circle(hCoord, meters, &area);
+ here_error_e error = StartDiscoveryPlace(area);
+ maps_area_destroy(area);
+ return error;
+}
+
+here_error_e HerePlace::StartDiscoveryPlace(maps_area_h hArea, const char *szAddr)
+{
+ if (!hArea)
+ return HERE_ERROR_INVALID_PARAMETER;
+
if (!m_pDiscoveryQuery)
return HERE_ERROR_OUT_OF_MEMORY;
- if (!hCoord)
- return HERE_ERROR_INVALID_PARAMETER;
- if (m_pDiscoveryQuery->GetSearchText().empty())
- {
- m_pDiscoveryQuery->SetType(DiscoveryQuery::QT_EXPLORE);
+ typedef enum {
+ PLACE_CMD_TEXT,
+ PLACE_CMD_CENTER,
+ PLACE_CMD_AREA,
+ } PlaceCmdType;
- double dLat, dLon;
- maps_coordinates_get_latitude(hCoord, &dLat);
- maps_coordinates_get_longitude(hCoord, &dLon);
- GeoCoordinates geoCoord(dLat, dLon);
+ PlaceCmdType cmdType;
+ maps_area_s *pArea = (maps_area_s*)hArea;
+ GeoCoordinates geoCoord;
+ GeoBoundingArea *geoArea = NULL;
+ GeoBoundingBox geoBox;
+ GeoBoundingCircle geoCircle;
- if (nDistance > 0)
- {
- GeoBoundingCircle geoCircle(geoCoord, nDistance);
- m_pDiscoveryQuery->SetArea(geoCircle);
- }
- else if (nDistance == 0)
- {
- m_pDiscoveryQuery->SetProximity(geoCoord);
- }
- else
- return HERE_ERROR_INVALID_PARAMETER;
- m_nRestReqId = m_pDiscoveryQuery->Execute(*this, NULL);
+ /* Merge search text with other search text being in preference */
+ String szSearchText = (szAddr ? szAddr : "");
+ if (m_pDiscoveryQuery->GetSearchText().size() > 0)
+ {
+ if (szSearchText.size() > 0) szSearchText += " ";
+ szSearchText += m_pDiscoveryQuery->GetSearchText();
+ }
+ m_pDiscoveryQuery->SetSearchText(szSearchText);
+
- return (m_nRestReqId > 0 ? HERE_ERROR_NONE : HERE_ERROR_INVALID_OPERATION);
+ /* Decide command type */
+ if (!szSearchText.empty())
+ {
+ cmdType = PLACE_CMD_TEXT;
+ }
+ else if (pArea->type == MAPS_AREA_CIRCLE && pArea->circle.radius == 0)
+ {
+ cmdType = PLACE_CMD_CENTER;
}
else
{
- here_error_e error;
- maps_area_h hArea = NULL;
- maps_area_create_circle(hCoord, nDistance, &hArea);
- error = StartDiscoveryPlaceByAddress(m_pDiscoveryQuery->GetSearchText().data(), hArea);
- maps_area_destroy(hArea);
- return error;
+ cmdType = PLACE_CMD_AREA;
}
-}
-here_error_e HerePlace::StartDiscoveryPlaceByArea(maps_area_h hArea)
-{
- if (!m_pDiscoveryQuery)
- return HERE_ERROR_OUT_OF_MEMORY;
-
- if (!hArea)
- return HERE_ERROR_INVALID_PARAMETER;
-
- if (m_pDiscoveryQuery->GetSearchText().empty())
+ /* Get proximity with area */
+ if (cmdType == PLACE_CMD_TEXT || cmdType == PLACE_CMD_CENTER)
{
- m_pDiscoveryQuery->SetType(DiscoveryQuery::QT_EXPLORE);
-
- maps_area_s *pArea = (maps_area_s*)hArea;
if (pArea->type == MAPS_AREA_RECTANGLE)
{
- GeoBoundingBox box(pArea->rect.top_left.longitude, pArea->rect.bottom_right.longitude,
- pArea->rect.bottom_right.latitude, pArea->rect.top_left.latitude);
- m_pDiscoveryQuery->SetArea(box);
+ double dLat1 = pArea->rect.top_left.latitude;
+ double dLng1 = pArea->rect.top_left.longitude;
+ double dLat2 = pArea->rect.bottom_right.latitude;
+ double dLng2 = pArea->rect.bottom_right.longitude;
+ double dLat = (dLat1 + dLat2) / 2;
+ double dLng = (dLng1 + dLng2) / 2;
+
+ geoCoord.SetLatitude(dLat);
+ geoCoord.SetLongitude(dLng);
}
- else if (pArea->type == MAPS_AREA_CIRCLE)
+ else if(pArea->type == MAPS_AREA_CIRCLE)
{
- GeoCoordinates coord(pArea->circle.center.latitude, pArea->circle.center.longitude);
- GeoBoundingCircle circle(coord, pArea->circle.radius);
- m_pDiscoveryQuery->SetArea(circle);
+ double dLat = pArea->circle.center.latitude;
+ double dLng = pArea->circle.center.longitude;
+
+ geoCoord.SetLatitude(dLat);
+ geoCoord.SetLongitude(dLng);
}
else
return HERE_ERROR_INVALID_PARAMETER;
-
-
- m_nRestReqId = m_pDiscoveryQuery->Execute(*this, NULL);
-
- return (m_nRestReqId > 0 ? HERE_ERROR_NONE : HERE_ERROR_INVALID_OPERATION);
}
- else
+ else if (cmdType == PLACE_CMD_AREA)
{
- return StartDiscoveryPlaceByAddress(m_pDiscoveryQuery->GetSearchText().data(), hArea);
+ if (pArea->type == MAPS_AREA_RECTANGLE)
+ {
+ HereUtils::Convert(hArea, geoBox);
+ geoArea = &geoBox;
+ }
+ else if (pArea->type == MAPS_AREA_CIRCLE)
+ {
+ HereUtils::Convert(hArea, geoCircle);
+ geoArea = &geoCircle;
+ }
+ else
+ return HERE_ERROR_INVALID_PARAMETER;
}
-}
-
-here_error_e HerePlace::StartDiscoveryPlaceByAddress(const char *szAddr, maps_area_h hArea)
-{
- if (!m_pDiscoveryQuery)
- return HERE_ERROR_OUT_OF_MEMORY;
- if (!szAddr || (szAddr && strlen(szAddr) <= 0) || !hArea)
- return HERE_ERROR_INVALID_PARAMETER;
-
- m_pDiscoveryQuery->SetType(DiscoveryQuery::QT_SEARCH);
-
- String szSearchText = szAddr;
- if (m_pDiscoveryQuery->GetSearchText().size() > 0 &&
- szSearchText != m_pDiscoveryQuery->GetSearchText())
+ /* Set properties */
+ if (cmdType == PLACE_CMD_TEXT)
{
- szSearchText += " " + m_pDiscoveryQuery->GetSearchText();
+ m_pDiscoveryQuery->SetType(DiscoveryQuery::QT_SEARCH);
+ m_pDiscoveryQuery->SetProximity(geoCoord);
}
- m_pDiscoveryQuery->SetSearchText(szSearchText);
-
- maps_area_s *pArea = (maps_area_s*)hArea;
- if (pArea->type == MAPS_AREA_RECTANGLE)
+ else if (cmdType == PLACE_CMD_CENTER)
{
- double dLat1 = pArea->rect.top_left.latitude;
- double dLng1 = pArea->rect.top_left.longitude;
- double dLat2 = pArea->rect.bottom_right.latitude;
- double dLng2 = pArea->rect.bottom_right.longitude;
- double dLat = (dLat1 + dLat2) / 2;
- double dLng = (dLng1 + dLng2) / 2;
-
- GeoCoordinates geoCoord(dLat, dLng);
+ m_pDiscoveryQuery->SetType(DiscoveryQuery::QT_EXPLORE);
m_pDiscoveryQuery->SetProximity(geoCoord);
}
- else if(pArea->type == MAPS_AREA_CIRCLE)
+ else
{
- double dLat = pArea->circle.center.latitude;
- double dLng = pArea->circle.center.longitude;
- GeoCoordinates geoCoord(dLat, dLng);
- m_pDiscoveryQuery->SetProximity(geoCoord);
+ m_pDiscoveryQuery->SetType(DiscoveryQuery::QT_EXPLORE);
+ if (geoArea)
+ m_pDiscoveryQuery->SetArea(*geoArea);
}
-
+ /* Execute query */
m_nRestReqId = m_pDiscoveryQuery->Execute(*this, NULL);
return (m_nRestReqId > 0 ? HERE_ERROR_NONE : HERE_ERROR_INVALID_OPERATION);
@@ -294,7 +312,7 @@ here_error_e HerePlace::PreparePlaceDetailsPreference(maps_preference_h hPref)
return HERE_ERROR_OUT_OF_MEMORY;
if (!hPref)
- return HERE_ERROR_INVALID_PARAMETER;
+ return HERE_ERROR_NONE;
int ret;
char *szLanguage = NULL;
@@ -303,22 +321,24 @@ here_error_e HerePlace::PreparePlaceDetailsPreference(maps_preference_h hPref)
m_pPlaceDetailsQuery->SetLanguage(szLanguage);
g_free(szLanguage);
+ maps_distance_unit_e eUnit;
+ ret = maps_preference_get_distance_unit(hPref, &eUnit);
+ if (ret == MAPS_ERROR_NONE)
+ m_eDistanceUnit = eUnit;
+
return HERE_ERROR_NONE;
}
-here_error_e HerePlace::StartPlaceDetails(const char *szPlaceId)
+here_error_e HerePlace::StartPlaceDetails(const char *szUrl)
{
if (!m_pPlaceDetailsQuery)
return HERE_ERROR_OUT_OF_MEMORY;
- if (!szPlaceId || (szPlaceId && strlen(szPlaceId) <= 0))
+ if (!szUrl || (szUrl && strlen(szUrl) <= 0))
return HERE_ERROR_INVALID_PARAMETER;
- m_pPlaceDetailsQuery->SetPlaceId(szPlaceId);
-
-
- m_nRestReqId = m_pPlaceDetailsQuery->Execute(*this, NULL);
+ m_nRestReqId = m_pPlaceDetailsQuery->Execute(*this, NULL, szUrl);
return (m_nRestReqId > 0 ? HERE_ERROR_NONE : HERE_ERROR_INVALID_OPERATION);
}
@@ -353,6 +373,11 @@ void HerePlace::OnDiscoverReply (const DiscoveryReply &Reply)
int error = MAPS_ERROR_UNKNOWN, sub_error;
bool is_valid, isPending;
+ if (m_bCanceled || !m_pCbFunc)
+ {
+ delete this;
+ return;
+ }
m_nReplyIdx = 0;
m_nReplyCnt = herePlaceList.size() + hereSearchList.size();
@@ -440,7 +465,8 @@ void HerePlace::OnDiscoverReply (const DiscoveryReply &Reply)
}
/* distance */
- maps_place_set_distance(mapsPlace, (int)herePlaceIt->GetDistance());
+ maps_place_set_distance(mapsPlace,
+ HereUtils::ConvertDistance((int)herePlaceIt->GetDistance(), m_eDistanceUnit) + 0.5);
/* sponser */
/* herePlaceList.GetIsSponsored() */
@@ -553,7 +579,14 @@ void HerePlace::OnDiscoverFailure(const DiscoveryReply& Reply)
void HerePlace::OnPlaceDetailsReply (const PlaceDetailsReply &Reply)
{
if (m_nReplyCnt == 0)
+ {
+ if (m_bCanceled || !m_pCbFunc)
+ {
+ delete this;
+ return;
+ }
m_nReplyCnt = 1;
+ }
PlaceDetails herePlace = Reply.GetPlaceDetails();
maps_place_h mapsPlace = NULL;
@@ -893,7 +926,7 @@ void HerePlace::ProcessPlaceCategory(PlaceDetails herePlace, maps_place_h mapsPl
}
void HerePlace::ProcessPlaceImage(PlaceDetails herePlace, maps_place_h mapsPlace)
-{
+{
ImageContentList hereImageList = herePlace.GetImageContent();
ImageContentList::iterator hereImage;
maps_item_list_h mapsImageList;
@@ -1205,7 +1238,7 @@ void HerePlace::__flushReplies(int error)
bool bCallbackCanceled = false;
int nReplyIdx = 0;
- if (m_bReplyFlushed) return;
+ if (m_bReplyFlushed || m_bCanceled || !m_pCbFunc) return;
m_bReplyFlushed = true;
__sortList(m_PlaceList);