*/
#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)
m_coordinates = GeoCoordinate(latitude, longitude);
}
-void Location::setCountry(QString country)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_country = country;
-}
-
void Location::setFormattedAddress(QString formattedAddress)
{
qDebug() << __PRETTY_FUNCTION__;
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);
}
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
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
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"];
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);