本文整理汇总了C++中QGeoCoordinate::setLatitude方法的典型用法代码示例。如果您正苦于以下问题:C++ QGeoCoordinate::setLatitude方法的具体用法?C++ QGeoCoordinate::setLatitude怎么用?C++ QGeoCoordinate::setLatitude使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QGeoCoordinate
的用法示例。
在下文中一共展示了QGeoCoordinate::setLatitude方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dragEnded
/*!
\internal
*/
void QDeclarativeRectangleMapItem::dragEnded()
{
QPointF newTopLeftPoint = QPointF(x(),y());
QGeoCoordinate newTopLeft = map()->screenPositionToCoordinate(newTopLeftPoint, false);
if (newTopLeft.isValid()) {
// calculate new geo width while checking for dateline crossing
const double lonW = bottomRight_.longitude() > topLeft_.longitude() ?
bottomRight_.longitude() - topLeft_.longitude() :
bottomRight_.longitude() + 360 - topLeft_.longitude();
const double latH = qAbs(bottomRight_.latitude() - topLeft_.latitude());
QGeoCoordinate newBottomRight;
// prevent dragging over valid min and max latitudes
if (QLocationUtils::isValidLat(newTopLeft.latitude() - latH)) {
newBottomRight.setLatitude(newTopLeft.latitude() - latH);
} else {
newBottomRight.setLatitude(QLocationUtils::clipLat(newTopLeft.latitude() - latH));
newTopLeft.setLatitude(newBottomRight.latitude() + latH);
}
// handle dateline crossing
newBottomRight.setLongitude(QLocationUtils::wrapLong(newTopLeft.longitude() + lonW));
newBottomRight.setAltitude(newTopLeft.altitude());
topLeft_ = newTopLeft;
bottomRight_ = newBottomRight;
geometry_.setPreserveGeometry(true, newTopLeft);
borderGeometry_.setPreserveGeometry(true, newTopLeft);
geometry_.markSourceDirty();
borderGeometry_.markSourceDirty();
updateMapItem();
emit topLeftChanged(topLeft_);
emit bottomRightChanged(bottomRight_);
}
}
示例2: newPosition
void GpsLocation::newPosition(QGeoPositionInfo pos)
{
int64_t lastTime = 0;
QGeoCoordinate lastCoord;
int nr = m_trackers.count();
if (nr) {
gpsTracker gt = m_trackers.last();
lastCoord.setLatitude(gt.latitude.udeg / 1000000.0);
lastCoord.setLongitude(gt.longitude.udeg / 1000000.0);
lastTime = gt.when;
}
// if we are waiting for a position update or
// if we have no record stored or if at least the configured minimum
// time has passed or we moved at least the configured minimum distance
int64_t delta = (int64_t)pos.timestamp().toTime_t() + gettimezoneoffset() - lastTime;
if (!nr || waitingForPosition || delta > prefs.time_threshold ||
lastCoord.distanceTo(pos.coordinate()) > prefs.distance_threshold) {
QString msg("received new position %1 after delta %2 threshold %3 (now %4 last %5)");
status(qPrintable(msg.arg(pos.coordinate().toString()).arg(delta).arg(prefs.time_threshold).arg(pos.timestamp().toString()).arg(QDateTime().fromMSecsSinceEpoch(lastTime * 1000).toString())));
waitingForPosition = false;
acquiredPosition();
gpsTracker gt;
gt.when = pos.timestamp().toTime_t();
gt.when += gettimezoneoffset(gt.when);
gt.latitude.udeg = lrint(pos.coordinate().latitude() * 1000000);
gt.longitude.udeg = lrint(pos.coordinate().longitude() * 1000000);
addFixToStorage(gt);
gpsTracker gtNew = m_trackers.last();
qDebug() << "newest fix is now at" << QDateTime().fromMSecsSinceEpoch(gtNew.when - gettimezoneoffset(gtNew.when) * 1000).toString();
}
}
示例3: readNextPosition
void CLbsPositionLogger::readNextPosition()
{
QByteArray line = m_logFile.readLine().trimmed();
if (line.isEmpty()) {
LOG_MODEL_ERROR("CLbsPositionLogger", "no readlien");
return;
}
QList<QByteArray> data = line.split(',');
QGeoCoordinate coordinate;
QGeoPositionInfo info;
bool hasTimestamp = false;
QDateTime timestamp = QDateTime::fromTime_t(data.value(0).toLong(&hasTimestamp), Qt::UTC);
if(hasTimestamp && timestamp.isValid())
info.setTimestamp(timestamp);
double latitude;
bool hasLatitude = false;
latitude = data.value(1).toDouble(&hasLatitude);
if(hasLatitude)
coordinate.setLatitude(latitude);
double longitude;
bool hasLongitude = false;
longitude = data.value(2).toDouble(&hasLongitude);
if(hasLongitude)
coordinate.setLongitude(longitude);
double altitude;
bool hasAltitude = false;
altitude = data.value(3).toDouble(&hasAltitude);
if(hasAltitude)
coordinate.setAltitude(altitude);
info.setCoordinate(coordinate);
double HorizontalAccuracy;
bool hasHorizontalAccuracy = false;
HorizontalAccuracy = data.value(4).toDouble(&hasHorizontalAccuracy);
if(hasHorizontalAccuracy)
info.setAttribute(QGeoPositionInfo::HorizontalAccuracy, HorizontalAccuracy);
double Direction;
bool hasDirection = false;
Direction = data.value(5).toDouble(&hasDirection);
if(hasDirection)
info.setAttribute(QGeoPositionInfo::Direction, Direction);
double GroundSpeed;
bool hasGroundSpeed = false;
GroundSpeed = data.value(6).toDouble(&hasGroundSpeed);
if(hasGroundSpeed)
info.setAttribute(QGeoPositionInfo::GroundSpeed, GroundSpeed);
if (info.isValid()) {
m_lastPosition = info;
emit positionUpdated(info);
}
}
示例4: geometryChanged
/*!
\internal
*/
void QDeclarativeRectangleMapItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
if (updatingGeometry_ || newGeometry.topLeft() == oldGeometry.topLeft()) {
QDeclarativeGeoMapItemBase::geometryChanged(newGeometry, oldGeometry);
return;
}
QDoubleVector2D newTopLeftPoint = QDoubleVector2D(x(),y());
QGeoCoordinate newTopLeft = map()->itemPositionToCoordinate(newTopLeftPoint, false);
if (newTopLeft.isValid()) {
// calculate new geo width while checking for dateline crossing
const double lonW = bottomRight_.longitude() > topLeft_.longitude() ?
bottomRight_.longitude() - topLeft_.longitude() :
bottomRight_.longitude() + 360 - topLeft_.longitude();
const double latH = qAbs(bottomRight_.latitude() - topLeft_.latitude());
QGeoCoordinate newBottomRight;
// prevent dragging over valid min and max latitudes
if (QLocationUtils::isValidLat(newTopLeft.latitude() - latH)) {
newBottomRight.setLatitude(newTopLeft.latitude() - latH);
} else {
newBottomRight.setLatitude(QLocationUtils::clipLat(newTopLeft.latitude() - latH));
newTopLeft.setLatitude(newBottomRight.latitude() + latH);
}
// handle dateline crossing
newBottomRight.setLongitude(QLocationUtils::wrapLong(newTopLeft.longitude() + lonW));
newBottomRight.setAltitude(newTopLeft.altitude());
topLeft_ = newTopLeft;
bottomRight_ = newBottomRight;
geometry_.setPreserveGeometry(true, newTopLeft);
borderGeometry_.setPreserveGeometry(true, newTopLeft);
markSourceDirtyAndUpdate();
emit topLeftChanged(topLeft_);
emit bottomRightChanged(bottomRight_);
}
// Not calling QDeclarativeGeoMapItemBase::geometryChanged() as it will be called from a nested
// call to this function.
}
示例5: geometryChanged
/*!
\internal
*/
void QDeclarativePolylineMapItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
if (updatingGeometry_ || newGeometry.topLeft() == oldGeometry.topLeft()) {
QDeclarativeGeoMapItemBase::geometryChanged(newGeometry, oldGeometry);
return;
}
QDoubleVector2D newPoint = QDoubleVector2D(x(),y()) + QDoubleVector2D(geometry_.firstPointOffset());
QGeoCoordinate newCoordinate = map()->screenPositionToCoordinate(newPoint, false);
if (newCoordinate.isValid()) {
double firstLongitude = path_.at(0).longitude();
double firstLatitude = path_.at(0).latitude();
double minMaxLatitude = firstLatitude;
// prevent dragging over valid min and max latitudes
for (int i = 0; i < path_.count(); ++i) {
double newLatitude = path_.at(i).latitude()
+ newCoordinate.latitude() - firstLatitude;
if (!QLocationUtils::isValidLat(newLatitude)) {
if (qAbs(newLatitude) > qAbs(minMaxLatitude)) {
minMaxLatitude = newLatitude;
}
}
}
// calculate offset needed to re-position the item within map border
double offsetLatitude = minMaxLatitude - QLocationUtils::clipLat(minMaxLatitude);
for (int i = 0; i < path_.count(); ++i) {
QGeoCoordinate coord = path_.at(i);
// handle dateline crossing
coord.setLongitude(QLocationUtils::wrapLong(coord.longitude()
+ newCoordinate.longitude() - firstLongitude));
coord.setLatitude(coord.latitude()
+ newCoordinate.latitude() - firstLatitude - offsetLatitude);
path_.replace(i, coord);
}
QGeoCoordinate leftBoundCoord = geometry_.geoLeftBound();
leftBoundCoord.setLongitude(QLocationUtils::wrapLong(leftBoundCoord.longitude()
+ newCoordinate.longitude() - firstLongitude));
geometry_.setPreserveGeometry(true, leftBoundCoord);
geometry_.markSourceDirty();
updateMapItem();
emit pathChanged();
}
// Not calling QDeclarativeGeoMapItemBase::geometryChanged() as it will be called from a nested
// call to this function.
}
示例6: startFlick
// FIXME:
// - not left right / up down flicking, so if map is rotated, will act unintuitively
void QDeclarativeGeoMapGestureArea::startFlick(int dx, int dy, int timeMs)
{
if (timeMs < 0)
return;
QGeoCoordinate animationStartCoordinate = map_->mapController()->center();
if (pan_.animation_->state() == QPropertyAnimation::Running)
pan_.animation_->stop();
QGeoCoordinate animationEndCoordinate = map_->mapController()->center();
pan_.animation_->setDuration(timeMs);
animationEndCoordinate.setLongitude(animationStartCoordinate.longitude() - (dx / pow(2.0, map_->mapController()->zoom())));
animationEndCoordinate.setLatitude(animationStartCoordinate.latitude() + (dy / pow(2.0, map_->mapController()->zoom())));
pan_.animation_->setStartValue(QVariant::fromValue(animationStartCoordinate));
pan_.animation_->setEndValue(QVariant::fromValue(animationEndCoordinate));
pan_.animation_->start();
emit flickStarted();
}
示例7: parseCoordinates
bool QGeoRouteXmlParser::parseCoordinates(QGeoCoordinate &coord)
{
QString currentElement = m_reader->name().toString();
m_reader->readNext();
while (!(m_reader->tokenType() == QXmlStreamReader::EndElement && m_reader->name() == currentElement)) {
if (m_reader->tokenType() == QXmlStreamReader::StartElement) {
QString name = m_reader->name().toString();
QString value = m_reader->readElementText();
if (name == "Latitude")
coord.setLatitude(value.toDouble());
else if (name == "Longitude")
coord.setLongitude(value.toDouble());
}
m_reader->readNext();
}
return true;
}
示例8: dragEnded
/*!
\internal
*/
void QDeclarativePolygonMapItem::dragEnded()
{
QPointF newPoint = QPointF(x(),y()) + geometry_.firstPointOffset();
QGeoCoordinate newCoordinate = map()->screenPositionToCoordinate(newPoint, false);
if (newCoordinate.isValid()) {
double firstLongitude = path_.at(0).longitude();
double firstLatitude = path_.at(0).latitude();
double minMaxLatitude = firstLatitude;
// prevent dragging over valid min and max latitudes
for (int i = 0; i < path_.count(); ++i) {
double newLatitude = path_.at(i).latitude()
+ newCoordinate.latitude() - firstLatitude;
if (!QLocationUtils::isValidLat(newLatitude)) {
if (qAbs(newLatitude) > qAbs(minMaxLatitude)) {
minMaxLatitude = newLatitude;
}
}
}
// calculate offset needed to re-position the item within map border
double offsetLatitude = minMaxLatitude - QLocationUtils::clipLat(minMaxLatitude);
for (int i = 0; i < path_.count(); ++i) {
QGeoCoordinate coord = path_.at(i);
// handle dateline crossing
coord.setLongitude(QLocationUtils::wrapLong(coord.longitude()
+ newCoordinate.longitude() - firstLongitude));
coord.setLatitude(coord.latitude()
+ newCoordinate.latitude() - firstLatitude - offsetLatitude);
path_.replace(i, coord);
}
QGeoCoordinate leftBoundCoord = geometry_.geoLeftBound();
leftBoundCoord.setLongitude(QLocationUtils::wrapLong(leftBoundCoord.longitude()
+ newCoordinate.longitude() - firstLongitude));
geometry_.setPreserveGeometry(true, leftBoundCoord);
borderGeometry_.setPreserveGeometry(true, leftBoundCoord);
geometry_.markSourceDirty();
borderGeometry_.markSourceDirty();
updateMapItem();
emit pathChanged();
}
}
示例9: changeCameraData
void QGeoTiledMapDataPrivate::changeCameraData(const QGeoCameraData &oldCameraData)
{
double lat = oldCameraData.center().latitude();
if (mapScene_->verticalLock()) {
QGeoCoordinate coord = map_->cameraData().center();
coord.setLatitude(lat);
map_->cameraData().setCenter(coord);
}
// For zoomlevel, "snap" 0.05 either side of a whole number.
// This is so that when we turn off bilinear scaling, we're
// snapped to the exact pixel size of the tiles
QGeoCameraData cam = map_->cameraData();
int izl = static_cast<int>(std::floor(cam.zoomLevel()));
float delta = cam.zoomLevel() - izl;
if (delta > 0.5) {
izl++;
delta -= 1.0;
}
if (qAbs(delta) < 0.05) {
cam.setZoomLevel(izl);
}
cameraTiles_->setCamera(cam);
mapScene_->setCameraData(cam);
mapScene_->setVisibleTiles(cameraTiles_->tiles());
if (tileRequests_) {
// don't request tiles that are already built and textured
QList<QSharedPointer<QGeoTileTexture> > cachedTiles =
tileRequests_->requestTiles(cameraTiles_->tiles() - mapScene_->texturedTiles());
foreach (const QSharedPointer<QGeoTileTexture> &tex, cachedTiles) {
mapScene_->addTile(tex->spec, tex);
}
if (!cachedTiles.isEmpty())
map_->update();
}
示例10: file
QList<QGeoPositionInfo> gpxfile::loadFrom(const QString fileName) {
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "File open error:" << file.errorString();
// return false;
}
QXmlStreamReader xml(&file);
QList<QGeoPositionInfo> trackList;
trackList.clear();
QGeoPositionInfo tp;
QGeoCoordinate coord;
QDateTime ts;
while (!xml.atEnd() && !xml.hasError())
{
xml.readNext();
if (xml.isStartElement()) {
if (xml.name() == "trkpt") {
coord.setLongitude(xml.attributes().value("lon").toFloat());
coord.setLatitude(xml.attributes().value("lat").toFloat());
while (xml.readNextStartElement()) {
if (xml.name() == "ele")
coord.setAltitude(xml.readElementText().toFloat());
else if (xml.name() == "time")
ts = QDateTime::fromString(xml.readElementText(),"yyyy-MM-dd'T'hh:mm:ss'Z'");
} //ele, time
tp.setCoordinate(coord);
tp.setTimestamp(ts);
trackList.append(tp);
} //trkpt
} //content
} //eof
return(trackList);
}
示例11: writeToSensorData
SensorData CzmlReader::writeToSensorData(QJsonObject& data)
{
QJsonArray positionArray;
QJsonObject positionObject;
SensorData sensordata;
QString id = data["id"].toString();
sensordata.setId(getIdFromCzmlString(id));
positionObject = data["position"].toObject();
positionArray = positionObject["cartographicDegrees"].toArray();
QGeoCoordinate parsedPosition;
parsedPosition.setLatitude(positionArray[1].toDouble());
parsedPosition.setLongitude(positionArray[0].toDouble());
sensordata.setPosition(parsedPosition);
sensordata.setHeight(positionArray[2].toDouble());
if(data["sensorvalue"].isString())
sensordata.setSensorValue(std::numeric_limits<double>::min());
else
sensordata.setSensorValue(data["sensorvalue"].toDouble());
return sensordata;
}
示例12: fitViewportToGeoShape
void QDeclarativeGeoMap::fitViewportToGeoShape()
{
int margins = 10;
if (!m_map || width() <= margins || height() <= margins)
return;
QGeoCoordinate topLeft;
QGeoCoordinate bottomRight;
switch (m_region.type()) {
case QGeoShape::RectangleType:
{
QGeoRectangle rect = m_region;
topLeft = rect.topLeft();
bottomRight = rect.bottomRight();
break;
}
case QGeoShape::CircleType:
{
const double pi = M_PI;
QGeoCircle circle = m_region;
QGeoCoordinate centerCoordinate = circle.center();
// calculate geo bounding box of the circle
// circle tangential points with meridians and the north pole create
// spherical triangle, we use spherical law of sines
// sin(lon_delta_in_rad)/sin(r_in_rad) =
// sin(alpha_in_rad)/sin(pi/2 - lat_in_rad), where:
// * lon_delta_in_rad - delta of longitudes of circle center
// and tangential points
// * r_in_rad - angular radius of the circle
// * lat_in_rad - latitude of circle center
// * alpha_in_rad - angle between meridian and radius to the circle =>
// this is tangential point => sin(alpha) = 1
// * lat_delta_in_rad - delta of latitudes of circle center and
// latitude of points where great circle (going through circle
// center) crosses circle and the pole
double r_in_rad = circle.radius() / EARTH_MEAN_RADIUS; // angular r
double lat_delta_in_deg = r_in_rad * 180 / pi;
double lon_delta_in_deg = std::asin(std::sin(r_in_rad) /
std::cos(centerCoordinate.latitude() * pi / 180)) * 180 / pi;
topLeft.setLatitude(centerCoordinate.latitude() + lat_delta_in_deg);
topLeft.setLongitude(centerCoordinate.longitude() - lon_delta_in_deg);
bottomRight.setLatitude(centerCoordinate.latitude()
- lat_delta_in_deg);
bottomRight.setLongitude(centerCoordinate.longitude()
+ lon_delta_in_deg);
// adjust if circle reaches poles => cross all meridians and
// fit into Mercator projection bounds
if (topLeft.latitude() > 90 || bottomRight.latitude() < -90) {
topLeft.setLatitude(qMin(topLeft.latitude(), 85.05113));
topLeft.setLongitude(-180.0);
bottomRight.setLatitude(qMax(bottomRight.latitude(),
-85.05113));
bottomRight.setLongitude(180.0);
}
break;
}
case QGeoShape::UnknownType:
//Fallthrough to default
default:
return;
}
// adjust zoom, use reference world to keep things simple
// otherwise we would need to do the error prone longitudes
// wrapping
QDoubleVector2D topLeftPoint =
m_map->referenceCoordinateToItemPosition(topLeft);
QDoubleVector2D bottomRightPoint =
m_map->referenceCoordinateToItemPosition(bottomRight);
double bboxWidth = bottomRightPoint.x() - topLeftPoint.x();
double bboxHeight = bottomRightPoint.y() - topLeftPoint.y();
// find center of the bounding box
QGeoCoordinate centerCoordinate =
m_map->referenceItemPositionToCoordinate(
(topLeftPoint + bottomRightPoint)/2);
// position camera to the center of bounding box
setCenter(centerCoordinate);
// if the shape is empty we just change center position, not zoom
if (bboxHeight == 0 && bboxWidth == 0)
return;
double zoomRatio = qMax(bboxWidth / (width() - margins),
bboxHeight / (height() - margins));
// fixme: use log2 with c++11
zoomRatio = std::log(zoomRatio) / std::log(2.0);
double newZoom = qMax((double)minimumZoomLevel(), m_map->mapController()->zoom()
- zoomRatio);
setZoomLevel(newZoom);
m_validRegion = true;
}
示例13: dt
void PsyUtils::TPositionInfo2QGeoPositionInfo(TPositionInfoBase &aPosInfoBase, QGeoPositionInfo& aQPosInfo)
{
if (aPosInfoBase.PositionClassType() & EPositionInfoClass ||
aPosInfoBase.PositionClassType() & EPositionSatelliteInfoClass) {
TPositionInfo *posInfo = static_cast<TPositionInfo*>(&aPosInfoBase);
TPosition pos;
QGeoCoordinate coord;
posInfo->GetPosition(pos);
coord.setLatitude(pos.Latitude());
coord.setLongitude(pos.Longitude());
coord.setAltitude(pos.Altitude());
//store the QGeoCoordinate values
aQPosInfo.setCoordinate(coord);
TDateTime datetime = pos.Time().DateTime();
QDateTime dt(QDate(datetime.Year() , datetime.Month() + 1, datetime.Day() + 1),
QTime(datetime.Hour() , datetime.Minute(), datetime.Second(),
datetime.MicroSecond() / 1000),
Qt::UTC);
//store the time stamp
aQPosInfo.setTimestamp(dt);
//store the horizontal accuracy
aQPosInfo.setAttribute(QGeoPositionInfo::HorizontalAccuracy, pos.HorizontalAccuracy());
//store the vertical accuracy
aQPosInfo.setAttribute(QGeoPositionInfo::VerticalAccuracy, pos.VerticalAccuracy());
if (aPosInfoBase.PositionClassType() & EPositionSatelliteInfoClass) {
TCourse course;
TPositionSatelliteInfo *satInfo = static_cast<TPositionSatelliteInfo*>(&aPosInfoBase);
satInfo->GetCourse(course);
aQPosInfo.setAttribute(QGeoPositionInfo::Direction, course.Heading());
aQPosInfo.setAttribute(QGeoPositionInfo::GroundSpeed, course.Speed());
aQPosInfo.setAttribute(QGeoPositionInfo::VerticalSpeed, course.VerticalSpeed());
}
}
if (aPosInfoBase.PositionClassType() & EPositionGenericInfoClass) {
HPositionGenericInfo *genInfo = static_cast<HPositionGenericInfo*>(&aPosInfoBase);
float val;
//check for the horizontal speed
if (genInfo->IsFieldAvailable(EPositionFieldHorizontalSpeed)) {
genInfo->GetValue(EPositionFieldHorizontalSpeed, val);
aQPosInfo.setAttribute(QGeoPositionInfo::GroundSpeed, val);
}
//check for the vertcal speed
if (genInfo->IsFieldAvailable(EPositionFieldVerticalSpeed)) {
genInfo->GetValue(EPositionFieldVerticalSpeed, val);
aQPosInfo.setAttribute(QGeoPositionInfo::VerticalSpeed, val);
}
//check for the magnetic variation
if (genInfo->IsFieldAvailable(EPositionFieldMagneticCourseError)) {
genInfo->GetValue(EPositionFieldMagneticCourseError, val);
aQPosInfo.setAttribute(QGeoPositionInfo::MagneticVariation, val);
}
//check for the heading
if (genInfo->IsFieldAvailable(EPositionFieldHeading)) {
genInfo->GetValue(EPositionFieldHeading, val);
aQPosInfo.setAttribute(QGeoPositionInfo::Direction, val);
}
}
}
示例14: setupFetchRequest
bool LandmarkFilterDialog::setupFetchRequest()
{
if (filterAllCheckBox->checkState() == Qt::Checked) {
fetchRequest->setFilter(QLandmarkFilter());
fetchRequest->setSorting(QLandmarkNameSort());
} else {
QLandmarkIntersectionFilter filter;
QLandmarkSortOrder sortOrder = QLandmarkNameSort();
if (filterNameCheckBox->checkState() == Qt::Checked) {
QLandmarkNameFilter nameFilter;
nameFilter.setName(nameLineEdit->text());
if (startsWithRadioButton->isChecked())
nameFilter.setMatchFlags(QLandmarkFilter::MatchStartsWith);
else
nameFilter.setMatchFlags(QLandmarkFilter::MatchContains);
filter.append(nameFilter);
}
if (filterCategoryCheckBox->checkState() == Qt::Checked) {
QLandmarkCategoryFilter categoryFilter;
if (categoryComboBox->count() > 0) {
oldCategoryId = categoryComboBox->itemData(categoryComboBox->currentIndex())
.value<QLandmarkCategoryId>();
categoryFilter.setCategoryId(oldCategoryId);
}
filter.append(categoryFilter);
}
if (filterBoxCheckBox->checkState() == Qt::Checked) {
if (!isValidLatitude(boxTopLeftLatitudeLineEdit->text())) {
QMessageBox::warning(this,"Warning", "Top left latitude is invalid. Must be between -90 and 90 (not inclusive)", QMessageBox::Ok, QMessageBox::NoButton);
return false;
}
else if (!isValidLongitude(boxTopLeftLongitudeLineEdit->text())) {
QMessageBox::warning(this,"Warning", "Top left longitude is invalid. Must be between -180 and 180 (inclusive) ", QMessageBox::Ok, QMessageBox::NoButton);
return false;
}
else if (!isValidLatitude(boxBottomRightLatitudeLineEdit->text())) {
QMessageBox::warning(this,"Warning", "Bottom right latitude is invalid. (Must be between -90 and 90 (not inclusive)", QMessageBox::Ok, QMessageBox::NoButton);
return false;
}
else if (!isValidLongitude(boxBottomRightLongitudeLineEdit->text())) {
QMessageBox::warning(this,"Warning", "Bottom right longitude is invalid. (Must be between -180 and 180 (inclusive)", QMessageBox::Ok, QMessageBox::NoButton);
return false;
}
QGeoCoordinate topLeft;
topLeft.setLatitude(boxTopLeftLatitudeLineEdit->text().toDouble());
topLeft.setLongitude(boxTopLeftLongitudeLineEdit->text().toDouble());
QGeoCoordinate bottomRight;
bottomRight.setLatitude(boxBottomRightLatitudeLineEdit->text().toDouble());
bottomRight.setLongitude(boxBottomRightLongitudeLineEdit->text().toDouble());
QGeoBoundingBox box;
box.setTopLeft(topLeft);
box.setBottomRight(bottomRight);
QLandmarkBoxFilter boxFilter;
boxFilter.setBoundingBox(box);
filter.append(boxFilter);
}
if (filterProximityCheckBox->checkState() == Qt::Checked) {
if (!isValidLatitude(proximityLatitudeLineEdit->text())) {
QMessageBox::warning(this,"Warning", "Proximity latitude is invalid. It must be between -90 and 90 (not inclusive)", QMessageBox::Ok, QMessageBox::NoButton);
return false;
} else if (!isValidLongitude(proximityLongitudeLineEdit->text())) {
QMessageBox::warning(this,"Warning", "Proximity longitude is invalid. It must be between -180 and 180 (inclusive) ", QMessageBox::Ok, QMessageBox::NoButton);
return false;
}
bool ok;
qreal radius = radiusLineEdit->text().toDouble(&ok);
if (!ok) {
QMessageBox::warning(this,"Warning", "Proximity radius is invalid. It must be a number", QMessageBox::Ok, QMessageBox::NoButton);
return false;
}
QLandmarkProximityFilter proximityFilter;
QGeoCoordinate center;
center.setLatitude(proximityLatitudeLineEdit->text().toDouble());
center.setLongitude(proximityLongitudeLineEdit->text().toDouble());
proximityFilter.setCenter(center);
proximityFilter.setRadius(radiusLineEdit->text().toDouble());
filter.append(proximityFilter);
sortOrder = QLandmarkSortOrder();
}
fetchRequest->setFilter(filter);
fetchRequest->setSorting(sortOrder);
}
return true;
}
示例15: networkReplyFinished
void QGeoCodeReplyOsm::networkReplyFinished()
{
if (!m_reply)
return;
if (m_reply->error() != QNetworkReply::NoError)
return;
QList<QGeoLocation> locations;
QJsonDocument document = QJsonDocument::fromJson(m_reply->readAll());
if (document.isObject()) {
QJsonObject object = document.object();
QGeoCoordinate coordinate;
coordinate.setLatitude(object.value(QStringLiteral("lat")).toString().toDouble());
coordinate.setLongitude(object.value(QStringLiteral("lon")).toString().toDouble());
QGeoLocation location;
location.setCoordinate(coordinate);
location.setAddress(parseAddressObject(object));
locations.append(location);
setLocations(locations);
} else if (document.isArray()) {
QJsonArray results = document.array();
for (int i = 0; i < results.count(); ++i) {
if (!results.at(i).isObject())
continue;
QJsonObject object = results.at(i).toObject();
QGeoCoordinate coordinate;
coordinate.setLatitude(object.value(QStringLiteral("lat")).toString().toDouble());
coordinate.setLongitude(object.value(QStringLiteral("lon")).toString().toDouble());
QGeoRectangle rectangle;
if (object.contains(QStringLiteral("boundingbox"))) {
QJsonArray a = object.value(QStringLiteral("boundingbox")).toArray();
if (a.count() == 4) {
rectangle.setTopLeft(QGeoCoordinate(a.at(1).toString().toDouble(),
a.at(2).toString().toDouble()));
rectangle.setBottomRight(QGeoCoordinate(a.at(0).toString().toDouble(),
a.at(3).toString().toDouble()));
}
}
QGeoLocation location;
location.setCoordinate(coordinate);
location.setBoundingBox(rectangle);
location.setAddress(parseAddressObject(object));
locations.append(location);
}
}
setLocations(locations);
setFinished(true);
m_reply->deleteLater();
m_reply = 0;
}