QTweetPlace QTweetConvert::jsonObjectToPlace(const QJsonObject& jsonObject) { QTweetPlace place; place.setName(jsonObject["name"].toString()); place.setCountryCode(jsonObject["country_code"].toString()); place.setCountry(jsonObject["country"].toString()); place.setID(jsonObject["id"].toString()); place.setFullName(jsonObject["full_name"].toString()); QString placeType = jsonObject["place_type"].toString(); if (placeType == "poi") place.setType(QTweetPlace::Poi); else if (placeType == "neighborhood") place.setType(QTweetPlace::Neighborhood); else if (placeType == "city") place.setType(QTweetPlace::City); else if (placeType == "admin") place.setType(QTweetPlace::Admin); else if (placeType == "country") place.setType(QTweetPlace::Country); else place.setType(QTweetPlace::Neighborhood); //twitter default QJsonValue bbJsonValue = jsonObject["bounding_box"]; if (!bbJsonValue.isNull()) { QJsonObject bbJsonObject = bbJsonValue.toObject(); if (bbJsonObject["type"].toString() == "Polygon") { QJsonArray coordList = bbJsonObject["coordinates"].toArray(); if (coordList.count() == 1) { QJsonArray latLongList = coordList[0].toArray(); if (latLongList.count() == 4) { QTweetGeoBoundingBox box; QJsonArray coordsBottomLeft = latLongList[0].toArray(); box.setBottomLeft(QTweetGeoCoord(coordsBottomLeft[1].toDouble(), coordsBottomLeft[0].toDouble())); QJsonArray coordsBottomRight = latLongList[1].toArray(); box.setBottomRight(QTweetGeoCoord(coordsBottomRight[1].toDouble(), coordsBottomRight[0].toDouble())); QJsonArray coordsTopRight = latLongList[2].toArray(); box.setTopRight(QTweetGeoCoord(coordsTopRight[1].toDouble(), coordsTopRight[0].toDouble())); QJsonArray coordsTopLeft = latLongList[3].toArray(); box.setTopLeft(QTweetGeoCoord(coordsTopLeft[1].toDouble(), coordsTopLeft[0].toDouble())); place.setBoundingBox(box); } } } } return place; }
void GeoReverse::onSearchPushButtonClicked() { QTweetGeoReverseGeoCode *reverseGeo = new QTweetGeoReverseGeoCode(m_oauthTwitter, this); reverseGeo->getPlaces(QTweetGeoCoord(ui->latitudeLineEdit->text().toDouble(), ui->longitudeLineEdit->text().toDouble())); connect(reverseGeo, SIGNAL(parsedPlaces(QList<QTweetPlace>)), SLOT(reverseGeoFinished(QList<QTweetPlace>))); }
//not to be used in timelines api, but in geo api, where place contains other places //is it recursive responsive? QTweetPlace QTweetConvert::jsonObjectToPlaceRecursive(const QJsonObject& jsonObject) { QTweetPlace place; place.setName(jsonObject["name"].toString()); place.setCountryCode(jsonObject["country_code"].toString()); place.setCountry(jsonObject["country"].toString()); place.setID(jsonObject["id"].toString()); place.setFullName(jsonObject["full_name"].toString()); QString placeType = jsonObject["place_type"].toString(); if (placeType == "poi") place.setType(QTweetPlace::Poi); else if (placeType == "neighborhood") place.setType(QTweetPlace::Neighborhood); else if (placeType == "city") place.setType(QTweetPlace::City); else if (placeType == "admin") place.setType(QTweetPlace::Admin); else if (placeType == "country") place.setType(QTweetPlace::Country); else place.setType(QTweetPlace::Neighborhood); //twitter default QJsonValue bbVar = jsonObject["bounding_box"]; if (!bbVar.isNull()) { QJsonObject bbObject = bbVar.toObject(); if (bbObject["type"].toString() == "Polygon") { QJsonArray coordList = bbObject["coordinates"].toArray(); if (coordList.count() == 1) { QJsonArray latLongList = coordList[0].toArray(); if (latLongList.count() == 4) { QTweetGeoBoundingBox box; QJsonArray coordsBottomLeft = latLongList[0].toArray(); box.setBottomLeft(QTweetGeoCoord(coordsBottomLeft[1].toDouble(), coordsBottomLeft[0].toDouble())); QJsonArray coordsBottomRight = latLongList[1].toArray(); box.setBottomRight(QTweetGeoCoord(coordsBottomRight[1].toDouble(), coordsBottomRight[0].toDouble())); QJsonArray coordsTopRight = latLongList[2].toArray(); box.setTopRight(QTweetGeoCoord(coordsTopRight[1].toDouble(), coordsTopRight[0].toDouble())); QJsonArray coordsTopLeft = latLongList[3].toArray(); box.setTopLeft(QTweetGeoCoord(coordsTopLeft[1].toDouble(), coordsTopLeft[0].toDouble())); place.setBoundingBox(box); } } } } QJsonArray containedArray = jsonObject["contained_within"].toArray(); QList<QTweetPlace> containedInPlacesList; if (!containedArray.isEmpty()) { for (int i = 0; i < containedArray.size(); ++i) { QTweetPlace containedPlace = jsonObjectToPlaceRecursive(containedArray[i].toObject()); containedInPlacesList.append(containedPlace); } } place.setContainedWithin(containedInPlacesList); return place; }