Added bounds and addressComponents for Location class
authorlampehe-local <henri.lampela@ixonos.com>
Wed, 28 Jul 2010 09:45:20 +0000 (12:45 +0300)
committerlampehe-local <henri.lampela@ixonos.com>
Wed, 28 Jul 2010 09:45:20 +0000 (12:45 +0300)
Removed unnessesary methods from Location class
Removed unnessesary items from parseSearchResults in RoutinService

Reviewed by: Jussi Laitinen

src/routing/location.cpp
src/routing/location.h
src/routing/routingservice.cpp

index e247ac3..a9956f0 100644 (file)
 */
 
 #include <QDebug>
+#include <QStringList>
 
 #include "routingcommon.h"
 #include "location.h"
 
 
 Location::Location()
-    : m_postalCode(0),
-    m_streetNumber(0)
 {
     qDebug() << __PRETTY_FUNCTION__;
 }
 
-const GeoCoordinate& Location::coordinates() const
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    return m_coordinates;
-}
-
-const QString& Location::country() const
+QStringList Location::addressComponents()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    return m_country;
-}
+    QStringList list = m_formattedAddress.split(",");
+    QStringList trimmedList;
 
-const QString& Location::formattedAddress() const
-{
-    qDebug() << __PRETTY_FUNCTION__;
+    foreach(QString str, list) {
+        trimmedList.append(str.trimmed());
+    }
 
-    return m_formattedAddress;
+    return trimmedList;
 }
 
-const QString& Location::locality() const
+void Location::bounds(GeoCoordinate &swBound, GeoCoordinate &neBound)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    return m_locality;
+    swBound = m_swBound;
+    neBound = m_neBound;
 }
 
-const QString& Location::locationType() const
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    return m_locationType;
-}
-
-int Location::postalCode() const
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    return m_postalCode;
-}
-
-const QString& Location::street() const
+const GeoCoordinate& Location::coordinates() const
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    return m_street;
+    return m_coordinates;
 }
 
-int Location::streetNumber() const
+const QString& Location::formattedAddress() const
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    return m_streetNumber;
+    return m_formattedAddress;
 }
 
 void Location::setCoordinates(double latitude, double longitude)
@@ -95,13 +74,6 @@ void Location::setCoordinates(double latitude, double longitude)
     m_coordinates = GeoCoordinate(latitude, longitude);
 }
 
-void Location::setCountry(QString country)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_country = country;
-}
-
 void Location::setFormattedAddress(QString formattedAddress)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -109,37 +81,16 @@ void Location::setFormattedAddress(QString formattedAddress)
     m_formattedAddress = formattedAddress;
 }
 
-void Location::setLocality(QString locality)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_locality = locality;
-}
-
-void Location::setLocationType(QString locationType)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_locationType = locationType;
-}
-
-void Location::setPostalCode(int postalCode)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_postalCode = postalCode;
-}
-
-void Location::setStreet(QString street)
+void Location::setNEBound(double latitude, double longitude)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_street = street;
+    m_neBound = GeoCoordinate(latitude, longitude);
 }
 
-void Location::setStreetNumber(int streetNumber)
+void Location::setSWBound(double latitude, double longitude)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_streetNumber = streetNumber;
+    m_swBound = GeoCoordinate(latitude, longitude);
 }
index 63408d6..ae60194 100644 (file)
@@ -45,62 +45,34 @@ public:
     Location();
 
     /**
-    * @brief Gets the coordinates of the location
+    * @brief Gets the address components of the location
     *
-    * @returns coordinates of the location
+    * @returns list of address components
     */
-    const GeoCoordinate& coordinates() const;
+    QStringList addressComponents();
 
     /**
-    * @brief Gets the country of the location
+    * @brief Gets the bounds of the location
     *
-    * @returns country of the location
+    * @param swBound coordinates of the southwest bound
+    * @param neBound coordinates of the northeast bound
     */
-    const QString& country() const;
+    void bounds(GeoCoordinate &swBound, GeoCoordinate &neBound);
 
     /**
-    * @brief Gets the formatted address of the location
-    *        e.g. Oxford street 1, London W1, United kingdom
+    * @brief Gets the coordinates of the location
     *
     * @returns coordinates of the location
     */
-    const QString& formattedAddress() const;
-
-    /**
-    * @brief Gets the locality (city) of the location
-    *
-    * @returns locality of the location
-    */
-    const QString& locality() const;
-
-    /**
-    * @brief Gets the location type of the location
-    *        e.g. street_address
-    *
-    * @returns locationType of the location
-    */
-    const QString& locationType() const;
-
-    /**
-    * @brief Gets the postal code of the location
-    *
-    * @returns postalCode of the location (or zero)
-    */
-    int postalCode() const;
-
-    /**
-    * @brief Gets the street of the location
-    *
-    * @returns street of the location (or empty QString)
-    */
-    const QString& street() const;
+    const GeoCoordinate& coordinates() const;
 
     /**
-    * @brief Gets the street number of the location
+    * @brief Gets the formatted address of the location
+    *        e.g. Oxford street 1, London W1, United kingdom
     *
-    * @returns streetNumber of the location (or zero)
+    * @returns coordinates of the location
     */
-    int streetNumber() const;
+    const QString& formattedAddress() const;
 
     /**
     * @brief Sets the coordinates of the location
@@ -112,59 +84,36 @@ public:
     void setCoordinates(double latitude, double longitude);
 
     /**
-    * @brief Sets the country of the location
-    *
-    */
-    void setCountry(QString country);
-
-    /**
     * @brief Sets the formatted address of the location
     *
     */
     void setFormattedAddress(QString formattedAddress);
 
     /**
-    * @brief Sets the locality of the location
-    *
-    */
-    void setLocality(QString locality);
-
-    /**
-    * @brief Sets the location type of the location
-    *
-    */
-    void setLocationType(QString locationType);
-
-    /**
-    * @brief Sets the postal code of the location
-    *
-    */
-    void setPostalCode(int postalCode);
-
-    /**
-    * @brief Sets the street of the location
+    * @brief Sets the northeast bound of the location
+    *        creates GeoCoordinate object from given parameters
     *
+    * @param latitude latitude value (double)
+    * @param longitude longitude value (double)
     */
-    void setStreet(QString street);
+    void setNEBound(double latitude, double longitude);
 
     /**
-    * @brief Sets the street number of the location
+    * @brief Sets the southwest bound of the location
+    *        creates GeoCoordinate object from given parameters
     *
+    * @param latitude latitude value (double)
+    * @param longitude longitude value (double)
     */
-    void setStreetNumber(int streetNumber);
+    void setSWBound(double latitude, double longitude);
 
 private:
 
-    int m_postalCode;               ///< Placeholder for postal code
-    int m_streetNumber;             ///< Placeholder for street number
-
-    QString m_country;              ///< Placeholder for county
     QString m_formattedAddress;     ///< Placeholder for formatted address
-    QString m_locality;             ///< Placeholcer for locality
-    QString m_locationType;         ///< Placeholcer for location type
-    QString m_street;               ///< Placeholcer for street
 
     GeoCoordinate m_coordinates;    ///< Placeholcer for coordinates
+    GeoCoordinate m_neBound;        ///< Placeholder for northeast bound
+    GeoCoordinate m_swBound;        ///< Placeholder for southwest bound
 };
 
 #endif // LOCATION_H
index 9e6afb7..8a536a3 100644 (file)
@@ -139,32 +139,9 @@ void RoutingService::parseSearchResults(const QByteArray &jsonReply)
             foreach(QVariant hitVariant, result["results"].toList()) {
                 Location location;
                 QMap<QString, QVariant> hitMap = hitVariant.toMap();
-                foreach(QVariant hitTypeVariant, hitMap["types"].toList()) {
-                    QStringList hitTypeList = hitTypeVariant.toStringList();
-                    foreach(QString hitType, hitTypeList) {
-                        if(hitType != "political")
-                            location.setLocationType(hitType);
-                    }
-                }
+
                 location.setFormattedAddress(hitMap["formatted_address"].toString());
-                foreach(QVariant addrComponent, hitMap["address_components"].toList()) {
-                    QMap<QString, QVariant> addrComponentMap = addrComponent.toMap();
-                    foreach(QVariant addrType, addrComponentMap["types"].toList()) {
-                        QStringList addrTypeList = addrType.toStringList();
-                        foreach(QString type, addrTypeList) {
-                            if(type == "street_number")
-                                location.setStreetNumber(addrComponentMap["long_name"].toInt());
-                            else if(type == "route")
-                                location.setStreet(addrComponentMap["long_name"].toString());
-                            else if(type == "locality")
-                                location.setLocality(addrComponentMap["long_name"].toString());
-                            else if(type == "country")
-                                location.setCountry(addrComponentMap["long_name"].toString());
-                            else if(type == "postal_code")
-                                location.setPostalCode(addrComponentMap["long_name"].toInt());
-                        }
-                    }
-                }
+
                 QVariant geometryVariant = hitMap["geometry"];
                 QMap<QString, QVariant> geometryMap = geometryVariant.toMap();
                 QVariant locationVariant = geometryMap["location"];
@@ -172,6 +149,17 @@ void RoutingService::parseSearchResults(const QByteArray &jsonReply)
                 location.setCoordinates(locationMap["lat"].toDouble(),
                                         locationMap["lng"].toDouble());
 
+                QVariant boundsVariant = geometryMap["bounds"];
+                QMap<QString, QVariant> boundsMap = boundsVariant.toMap();
+                QVariant swVariant = boundsMap["southwest"];
+                QMap<QString, QVariant> swMap = swVariant.toMap();
+                location.setSWBound(swMap["lat"].toDouble(),
+                                    swMap["lng"].toDouble());
+                QVariant neVariant = boundsMap["northeast"];
+                QMap<QString, QVariant> neMap = neVariant.toMap();
+                location.setNEBound(neMap["lat"].toDouble(),
+                                    neMap["lng"].toDouble());
+
                 m_searchResults.append(location);
             }
             emit locationDataParsed(m_searchResults);