diff --git a/MobileClient/QtProject/src/Panel_NearbySpots.qml b/MobileClient/QtProject/src/Panel_NearbySpots.qml index 19b0f1f..aec2b83 100644 --- a/MobileClient/QtProject/src/Panel_NearbySpots.qml +++ b/MobileClient/QtProject/src/Panel_NearbySpots.qml @@ -91,6 +91,7 @@ Item { width: parent.width height: parent.height model: wa_NearbySpotModel + maxDistance_km: 150 onSpotClicked: { stackView.push({item: Qt.resolvedUrl("pages-spot/Page_Spot.qml"), properties:{width:stackView.width, diff --git a/MobileClient/QtProject/src/cpp/WebApi/NearbySpotsModel.cpp b/MobileClient/QtProject/src/cpp/WebApi/NearbySpotsModel.cpp index 6c34f1b..e520bed 100644 --- a/MobileClient/QtProject/src/cpp/WebApi/NearbySpotsModel.cpp +++ b/MobileClient/QtProject/src/cpp/WebApi/NearbySpotsModel.cpp @@ -63,12 +63,14 @@ QHash NearbySpotsModel::roleNames() const //----------------------------------------------------------------------------------------------------------------------------- -void NearbySpotsModel::setLocation(float latitude, - float longitude) +void NearbySpotsModel::setLocation(double latitude, + double longitude, + double maxDistance_km) { QList qList_QueryItems; - qList_QueryItems.append(QueryItem(WebApi::R_PARAM_LATITUDE, QString::number(latitude))); - qList_QueryItems.append(QueryItem(WebApi::R_PARAM_LONGITUDE, QString::number(longitude))); + qList_QueryItems.append(QueryItem(WebApi::R_PARAM_LATITUDE, QString::number(latitude))); + qList_QueryItems.append(QueryItem(WebApi::R_PARAM_LONGITUDE, QString::number(longitude))); + qList_QueryItems.append(QueryItem(WebApi::R_PARAM_MAX_DISTANCE_KM, QString::number(maxDistance_km))); // TODO check post return type m_Command_GetNearbySpots.postRequest(qList_QueryItems); @@ -99,7 +101,7 @@ void NearbySpotsModel::slot_CommandGetNearbySpots_Finished(const WebApiError &er qScriptValue_Ids.property(i).property(WebApi::A_ARRAY_SPOTS_ELEMENT_DESCRIPTION).toString(), qScriptValue_Ids.property(i).property(WebApi::A_ARRAY_SPOTS_ELEMENT_LATITUDE).toNumber(), qScriptValue_Ids.property(i).property(WebApi::A_ARRAY_SPOTS_ELEMENT_LONGITUDE).toNumber(), - qScriptValue_Ids.property(i).property(WebApi::A_ARRAY_SPOTS_ELEMENT_DISTANCE).toNumber(), + qScriptValue_Ids.property(i).property(WebApi::A_ARRAY_SPOTS_ELEMENT_DISTANCE_KM).toNumber(), qScriptValue_Ids.property(i).property(WebApi::A_ARRAY_SPOTS_ELEMENT_PICTURE_URL_1).toString(), qScriptValue_Ids.property(i).property(WebApi::A_ARRAY_SPOTS_ELEMENT_PICTURE_URL_2).toString())); } diff --git a/MobileClient/QtProject/src/cpp/WebApi/NearbySpotsModel.h b/MobileClient/QtProject/src/cpp/WebApi/NearbySpotsModel.h index d50b43a..a2e4ec6 100644 --- a/MobileClient/QtProject/src/cpp/WebApi/NearbySpotsModel.h +++ b/MobileClient/QtProject/src/cpp/WebApi/NearbySpotsModel.h @@ -40,8 +40,9 @@ class NearbySpotsModel : public QAbstractListModel public slots: - void setLocation(float latitude, - float longitude); + void setLocation(double latitude, + double longitude, + double maxDistance_km); private slots: void slot_CommandGetNearbySpots_Finished (const WebApiError &error); diff --git a/MobileClient/QtProject/src/cpp/WebApi/Spot.cpp b/MobileClient/QtProject/src/cpp/WebApi/Spot.cpp index cea2330..5c08a17 100644 --- a/MobileClient/QtProject/src/cpp/WebApi/Spot.cpp +++ b/MobileClient/QtProject/src/cpp/WebApi/Spot.cpp @@ -25,7 +25,7 @@ Spot::Spot(int id, QString description, qreal latitude, qreal longitude, - qreal distance, + qreal distance_km, QString pictureUrl1, QString pictureUrl2, QObject *parent) @@ -39,13 +39,13 @@ Spot::Spot(int id, m_PictureUrl1 (pictureUrl1), m_PictureUrl2 (pictureUrl2) { - if(distance >= 2) + if(distance_km >= 2) { - m_Distance = QString("%1 km").arg((int) distance); + m_Distance = QString("%1 km").arg((int) distance_km); } else { - m_Distance = QString("%1 m").arg((int) (distance*1000)); + m_Distance = QString("%1 m").arg((int) (distance_km*1000)); } if(m_PictureUrl1.isEmpty() == false) diff --git a/MobileClient/QtProject/src/cpp/WebApi/Spot.h b/MobileClient/QtProject/src/cpp/WebApi/Spot.h index a1aff6e..7473f77 100644 --- a/MobileClient/QtProject/src/cpp/WebApi/Spot.h +++ b/MobileClient/QtProject/src/cpp/WebApi/Spot.h @@ -35,7 +35,7 @@ class Spot : public QObject QString description, qreal latitude, qreal longitude, - qreal distance, + qreal distance_km, QString pictureUrl1, QString pictureUrl2, QObject *parent = 0); diff --git a/MobileClient/QtProject/src/cpp/WebApi/WebApi.cpp b/MobileClient/QtProject/src/cpp/WebApi/WebApi.cpp index 163e05b..1e4b10a 100644 --- a/MobileClient/QtProject/src/cpp/WebApi/WebApi.cpp +++ b/MobileClient/QtProject/src/cpp/WebApi/WebApi.cpp @@ -53,8 +53,9 @@ const QString WebApi::R_PARAM_EMAIL ("email"); const QString WebApi::R_PARAM_SPOT_ID ("id_spot"); -const QString WebApi::R_PARAM_LATITUDE ("latitude"); -const QString WebApi::R_PARAM_LONGITUDE ("longitude"); +const QString WebApi::R_PARAM_LATITUDE ("latitude"); +const QString WebApi::R_PARAM_LONGITUDE ("longitude"); +const QString WebApi::R_PARAM_MAX_DISTANCE_KM("maxDistance_km"); const QString WebApi::A_PARAM_AUTHENTICATION ("authentication"); const QString WebApi::A_PARAM_REGISTERED ("registered"); @@ -65,7 +66,7 @@ const QString WebApi::A_ARRAY_SPOTS_ELEMENT_NAME ("name"); const QString WebApi::A_ARRAY_SPOTS_ELEMENT_DESCRIPTION ("description"); const QString WebApi::A_ARRAY_SPOTS_ELEMENT_LATITUDE ("latitude"); const QString WebApi::A_ARRAY_SPOTS_ELEMENT_LONGITUDE ("longitude"); -const QString WebApi::A_ARRAY_SPOTS_ELEMENT_DISTANCE ("distance"); +const QString WebApi::A_ARRAY_SPOTS_ELEMENT_DISTANCE_KM ("distance_km"); const QString WebApi::A_ARRAY_SPOTS_ELEMENT_PICTURE_URL_1 ("pictureUrl1"); const QString WebApi::A_ARRAY_SPOTS_ELEMENT_PICTURE_URL_2 ("pictureUrl2"); diff --git a/MobileClient/QtProject/src/cpp/WebApi/WebApi.h b/MobileClient/QtProject/src/cpp/WebApi/WebApi.h index 8424bdc..dfb5ee0 100644 --- a/MobileClient/QtProject/src/cpp/WebApi/WebApi.h +++ b/MobileClient/QtProject/src/cpp/WebApi/WebApi.h @@ -70,6 +70,7 @@ class WebApi : public QObject static const QString R_PARAM_LATITUDE; static const QString R_PARAM_LONGITUDE; + static const QString R_PARAM_MAX_DISTANCE_KM; static const QString A_PARAM_AUTHENTICATION; static const QString A_PARAM_REGISTERED; @@ -80,7 +81,7 @@ class WebApi : public QObject static const QString A_ARRAY_SPOTS_ELEMENT_DESCRIPTION; static const QString A_ARRAY_SPOTS_ELEMENT_LATITUDE; static const QString A_ARRAY_SPOTS_ELEMENT_LONGITUDE; - static const QString A_ARRAY_SPOTS_ELEMENT_DISTANCE; + static const QString A_ARRAY_SPOTS_ELEMENT_DISTANCE_KM; static const QString A_ARRAY_SPOTS_ELEMENT_PICTURE_URL_1; static const QString A_ARRAY_SPOTS_ELEMENT_PICTURE_URL_2; diff --git a/MobileClient/QtProject/src/pages-spot/Page_SpotsList.qml b/MobileClient/QtProject/src/pages-spot/Page_SpotsList.qml index 3583193..2260963 100644 --- a/MobileClient/QtProject/src/pages-spot/Page_SpotsList.qml +++ b/MobileClient/QtProject/src/pages-spot/Page_SpotsList.qml @@ -25,20 +25,27 @@ BasicPage{ continueButtonVisible: false menuButtonVisible: false + // Properties -------------------------- + property double maxDistance_km: 150 + // Bind properties --------------------- property alias model: listView.model // Signals ----------------------------- signal spotClicked(int spotId, string spotName, string spotDescription) + // Connections ------------------------- onVisibleChanged: { if(visible == false) { return; } + console.log("wa_NearbySpotModel.setLocation") + wa_NearbySpotModel.setLocation(hc_LocationManager.latitude(), - hc_LocationManager.longitude()); + hc_LocationManager.longitude(), + maxDistance_km); } // Gui --------------------------------- diff --git a/MobileClient/QtProject/src/pages-upload/NearbySpotSelection.qml b/MobileClient/QtProject/src/pages-upload/NearbySpotSelection.qml index a9f22ac..653bf55 100644 --- a/MobileClient/QtProject/src/pages-upload/NearbySpotSelection.qml +++ b/MobileClient/QtProject/src/pages-upload/NearbySpotSelection.qml @@ -52,6 +52,7 @@ BasicPage{ anchors.top: button_AddNewSpot.bottom anchors.bottom: parent.bottom model: wa_NearbySpotModel + maxDistance_km: 4 onSpotClicked: { wa_PictureUploader.setNewSpot(false); wa_PictureUploader.setExistingSpotId(spotId); diff --git a/WebSite/Symfony/src/Instaspots/SpotsBundle/Controller/WebserviceController.php b/WebSite/Symfony/src/Instaspots/SpotsBundle/Controller/WebserviceController.php index ad78e05..393dd5a 100644 --- a/WebSite/Symfony/src/Instaspots/SpotsBundle/Controller/WebserviceController.php +++ b/WebSite/Symfony/src/Instaspots/SpotsBundle/Controller/WebserviceController.php @@ -91,8 +91,9 @@ public function webserviceAction(Request $request) case "getNearbySpots": $this->getNearbySpots($response, - $request->get('latitude' ), - $request->get('longitude')); + $request->get('latitude' ), + $request->get('longitude'), + $request->get('maxDistance_km')); break; default: @@ -435,7 +436,7 @@ private function getPictures( &$response, private function getNearbySpots( &$response, $latitude, $longitude, - $distance_km = 150) + $maxDistance_km) { $repository = $this->getDoctrine() ->getManager() @@ -444,7 +445,7 @@ private function getNearbySpots( &$response, $jSpots = array(); foreach($repository->getArrayByDistance($latitude, $longitude, - $distance_km) + $maxDistance_km) as &$spot) { $jSpot = array(); @@ -454,7 +455,7 @@ private function getNearbySpots( &$response, $jSpot['description'] = $spot[0]['description']; $jSpot['latitude'] = $spot[0]['latitude']; $jSpot['longitude'] = $spot[0]['longitude']; - $jSpot['distance'] = $spot['distance']; + $jSpot['distance_km'] = $spot['distance']; $picture1 = new Picture(); $picture1->setId ($spot[0]['picture1']['id']);