void MapWidget::setGeo(const QGeoCoordinate &geo) { p->image = QImage(":/qml/Papyrus/files/map-loading.png").scaled(width(),height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); update(); if( !geo.latitude() && !geo.longitude() ) return; if( p->reply ) return; init_manager(); p->geo = geo; QString path = "http://maps.google.com/maps/api/staticmap?center=" + QString::number(geo.latitude()) + "," + QString::number(geo.longitude()) + "&zoom=15&size=" + QString::number(width()) + "x" + QString::number(height()) + "&sensor=false"; QNetworkRequest request = QNetworkRequest(QUrl(path)); p->reply = p->manager->get(request); connect(p->reply, SIGNAL(sslErrors(QList<QSslError>)), SLOT(sslErrors(QList<QSslError>))); connect(p->reply, SIGNAL(downloadProgress(qint64,qint64)), SLOT(downloadProgress(qint64,qint64)) ); setToolTip( QString::number(p->geo.latitude()) + ", " + QString::number(p->geo.longitude()) ); }
/*! \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_); } }
void PointInPolygonWidget::positionUpdated(const QGeoPositionInfo &info) { QGeoPositionInfo pos_info = info; QGeoCoordinate pos = pos_info.coordinate(); if (pos.isValid()) { ui->xNewPoint->setValue(pos.latitude()); ui->yNewPoint->setValue(pos.longitude()); ui->xPoint->setValue(pos.latitude()); ui->yPoint->setValue(pos.longitude()); double dist = 0; if (is_first_distance_) { dist_acc_ = 0; is_first_distance_ = false; } else { if (std::fabs(pos.altitude()) < 1e-3) { pos.setAltitude(last_position_.coordinate().altitude()); pos_info.setCoordinate(pos); } dist = pos_info.coordinate().distanceTo(last_position_.coordinate()); if (dist > 10) { dist_acc_ += dist; } } last_position_ = pos_info; } }
// A workaround for circle path to be drawn correctly using a polygon geometry void QDeclarativeCircleMapItem::updateCirclePathForRendering(QList<QGeoCoordinate> &path, const QGeoCoordinate ¢er, qreal distance) { qreal poleLat = 90; qreal distanceToNorthPole = center.distanceTo(QGeoCoordinate(poleLat, 0)); qreal distanceToSouthPole = center.distanceTo(QGeoCoordinate(-poleLat, 0)); bool crossNorthPole = distanceToNorthPole < distance; bool crossSouthPole = distanceToSouthPole < distance; if (!crossNorthPole && !crossSouthPole) return; QList<int> wrapPathIndex; // calculate actual width of map on screen in pixels QDoubleVector2D midPoint = map()->coordinateToItemPosition(map()->cameraData().center(), false); QDoubleVector2D midPointPlusOne(midPoint.x() + 1.0, midPoint.y()); QGeoCoordinate coord1 = map()->itemPositionToCoordinate(midPointPlusOne, false); qreal geoDistance = coord1.longitude() - map()->cameraData().center().longitude(); if ( geoDistance < 0 ) geoDistance += 360; qreal mapWidth = 360.0 / geoDistance; mapWidth = qMin(static_cast<int>(mapWidth), map()->width()); QDoubleVector2D prev = map()->coordinateToItemPosition(path.at(0), false); // find the points in path where wrapping occurs for (int i = 1; i <= path.count(); ++i) { int index = i % path.count(); QDoubleVector2D point = map()->coordinateToItemPosition(path.at(index), false); if ( (qAbs(point.x() - prev.x())) >= mapWidth/2.0 ) { wrapPathIndex << index; if (wrapPathIndex.size() == 2 || !(crossNorthPole && crossSouthPole)) break; } prev = point; } // insert two additional coords at top/bottom map corners of the map for shape // to be drawn correctly if (wrapPathIndex.size() > 0) { qreal newPoleLat = 90; QGeoCoordinate wrapCoord = path.at(wrapPathIndex[0]); if (wrapPathIndex.size() == 2) { QGeoCoordinate wrapCoord2 = path.at(wrapPathIndex[1]); if (wrapCoord2.latitude() > wrapCoord.latitude()) newPoleLat = -90; } else if (center.latitude() < 0) { newPoleLat = -90; } for (int i = 0; i < wrapPathIndex.size(); ++i) { int index = wrapPathIndex[i] == 0 ? 0 : wrapPathIndex[i] + i*2; int prevIndex = (index - 1) < 0 ? (path.count() - 1): index - 1; QGeoCoordinate coord0 = path.at(prevIndex); QGeoCoordinate coord1 = path.at(index); coord0.setLatitude(newPoleLat); coord1.setLatitude(newPoleLat); path.insert(index ,coord1); path.insert(index, coord0); newPoleLat = -newPoleLat; } } }
/*! Sets the center of this geo rectangle to \a center. If this causes the geo rectangle to cross on of the poles the height of the geo rectangle will be truncated such that the geo rectangle only extends up to the pole. The center of the geo rectangle will be unchanged, and the height will be adjusted such that the center point is at the center of the truncated geo rectangle. */ void QGeoRectangle::setCenter(const QGeoCoordinate ¢er) { Q_D(QGeoRectangle); if (!isValid()) { d->topLeft = center; d->bottomRight = center; return; } double width = this->width(); double height = this->height(); double tlLat = center.latitude() + height / 2.0; double tlLon = center.longitude() - width / 2.0; double brLat = center.latitude() - height / 2.0; double brLon = center.longitude() + width / 2.0; if (tlLon < -180.0) tlLon += 360.0; if (tlLon > 180.0) tlLon -= 360.0; if (brLon < -180.0) brLon += 360.0; if (brLon > 180.0) brLon -= 360.0; if (tlLat > 90.0) { brLat = 2 * center.latitude() - 90.0; tlLat = 90.0; } if (tlLat < -90.0) { brLat = -90.0; tlLat = -90.0; } if (brLat > 90.0) { tlLat = 90.0; brLat = 90.0; } if (brLat < -90.0) { tlLat = 2 * center.latitude() + 90.0; brLat = -90.0; } if (width == 360.0) { tlLon = -180.0; brLon = 180.0; } d->topLeft = QGeoCoordinate(tlLat, tlLon); d->bottomRight = QGeoCoordinate(brLat, brLon); }
void latitude() { QFETCH(double, value); QGeoCoordinate c; c.setLatitude(value); QCOMPARE(c.latitude(), value); QGeoCoordinate c2 = c; QCOMPARE(c.latitude(), value); QCOMPARE(c2, c); }
/*! Sets the center of this bounding box to \a center. If this causes the bounding box to cross on of the poles the height of the bounding box will be truncated such that the bounding box only extends up to the pole. The center of the bounding box will be unchanged, and the height will be adjusted such that the center point is at the center of the truncated bounding box. */ void QGeoBoundingBox::setCenter(const QGeoCoordinate ¢er) { double width = this->width(); double height = this->height(); double tlLat = center.latitude() + height / 2.0; double tlLon = center.longitude() - width / 2.0; double brLat = center.latitude() - height / 2.0; double brLon = center.longitude() + width / 2.0; if (tlLon < -180.0) tlLon += 360.0; if (tlLon > 180.0) tlLon -= 360.0; if (brLon < -180.0) brLon += 360.0; if (brLon > 180.0) brLon -= 360.0; if (tlLat > 90.0) { brLat = 2* center.latitude() - 90.0; tlLat = 90.0; } if (tlLat < -90.0) { brLat = -90.0; tlLat = -90.0; } if (brLat > 90.0) { tlLat = 90.0; brLat = 90.0; } if (brLat < -90.0) { tlLat = 2 * center.latitude() + 90.0; brLat = -90.0; } if (width == 360.0) { tlLon = -180.0; brLon = 180.0; } d_ptr->topLeft = QGeoCoordinate(tlLat, tlLon); d_ptr->bottomRight = QGeoCoordinate(brLat, brLon); }
void MainWindow::positionUpdated(QGeoPositionInfo geoPositionInfo) { if (geoPositionInfo.isValid()) { // Stop regular position updates, because a valid position has been // obtained locationDataSource->stopUpdates(); // Get the current location as latitude and longitude QGeoCoordinate geoCoordinate = geoPositionInfo.coordinate(); qreal latitude = geoCoordinate.latitude(); qreal longitude = geoCoordinate.longitude(); QString string1; QString string2; // QChar c = 'g'; //build the string for latitude-longitude string1.setNum(latitude); this->latlng.append(string1); string2.setNum(longitude); this->latlng.append(","); this->latlng.append(string2); //send the location request sendRequest(); } }
void QTMLocationProvider::positionUpdated(const QGeoPositionInfo &geoPosition) { if (!geoPosition.isValid()) { NS_WARNING("Invalida geoposition received"); return; } QGeoCoordinate coord = geoPosition.coordinate(); double latitude = coord.latitude(); double longitude = coord.longitude(); double altitude = coord.altitude(); double accuracy = geoPosition.attribute(QGeoPositionInfo::HorizontalAccuracy); double altitudeAccuracy = geoPosition.attribute(QGeoPositionInfo::VerticalAccuracy); double heading = geoPosition.attribute(QGeoPositionInfo::Direction); bool providesSpeed = geoPosition.hasAttribute(QGeoPositionInfo::GroundSpeed); double speed = geoPosition.attribute(QGeoPositionInfo::GroundSpeed); nsRefPtr<nsGeoPosition> p = new nsGeoPosition(latitude, longitude, altitude, accuracy, altitudeAccuracy, heading, speed, geoPosition.timestamp().toTime_t()); if (mCallback) { mCallback->Update(p); } }
/*! Sets the bottom left coordinate of this geo rectangle to \a bottomLeft. */ void QGeoRectangle::setBottomLeft(const QGeoCoordinate &bottomLeft) { Q_D(QGeoRectangle); d->bottomRight.setLatitude(bottomLeft.latitude()); d->topLeft.setLongitude(bottomLeft.longitude()); }
void GeolocationClientQt::positionUpdated(const QGeoPositionInfo &geoPosition) { if (!geoPosition.isValid()) return; QGeoCoordinate coord = geoPosition.coordinate(); double latitude = coord.latitude(); double longitude = coord.longitude(); bool providesAltitude = (geoPosition.coordinate().type() == QGeoCoordinate::Coordinate3D); double altitude = coord.altitude(); double accuracy = geoPosition.attribute(QGeoPositionInfo::HorizontalAccuracy); bool providesAltitudeAccuracy = geoPosition.hasAttribute(QGeoPositionInfo::VerticalAccuracy); double altitudeAccuracy = geoPosition.attribute(QGeoPositionInfo::VerticalAccuracy); bool providesHeading = geoPosition.hasAttribute(QGeoPositionInfo::Direction); double heading = geoPosition.attribute(QGeoPositionInfo::Direction); bool providesSpeed = geoPosition.hasAttribute(QGeoPositionInfo::GroundSpeed); double speed = geoPosition.attribute(QGeoPositionInfo::GroundSpeed); double timeStampInSeconds = geoPosition.timestamp().toMSecsSinceEpoch() / 1000; m_lastPosition = GeolocationPosition::create(timeStampInSeconds, latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed); WebCore::Page* page = QWebPagePrivate::core(m_page); page->geolocationController()->positionChanged(m_lastPosition.get()); }
SlippyCoordinates::SlippyCoordinates(QGeoCoordinate location, int zoom, QObject *parent): QObject(parent) { this->m_zoom=zoom; // for the calculation see: // http://wiki.openstreetmap.org/wiki/Tilenames#X_and_Y double latitude=location.latitude(); double longitude=location.longitude(); qDebug() << "New Coordinates " << latitude << ", " << longitude; //check for either to be NaN if(latitude!=latitude || longitude!=longitude) { setValid(false); return; } double mercatorx = ((longitude + 180) / 360); double mercatory = (1.0 - (log(tan(latitude/180.0*M_PI) + sec(latitude/180.0*M_PI)) / M_PI)) / 2.0; setMercatorPos(QPointF(mercatorx, mercatory)); }
/*! Returns whether the coordinate \a coordinate is contained within this bounding box. */ bool QGeoBoundingBox::contains(const QGeoCoordinate &coordinate) const { if (!isValid() || !coordinate.isValid()) return false; double left = d_ptr->topLeft.longitude(); double right = d_ptr->bottomRight.longitude(); double top = d_ptr->topLeft.latitude(); double bottom = d_ptr->bottomRight.latitude(); double lon = coordinate.longitude(); double lat = coordinate.latitude(); if (lat > top) return false; if (lat < bottom) return false; if ((lat == 90.0) && (top == 90.0)) return true; if ((lat == -90.0) && (bottom == -90.0)) return true; if (left <= right) { if ((lon < left) || (lon > right)) return false; } else { if ((lon < left) && (lon > right)) return false; } return true; }
void OpenstreetmapMapProvider::getTiles(const QGeoCoordinate& topleft, int zoomLevel, int width, int height) { cancelDownload(); double tilex_exact = long2tilex(topleft.longitude(), zoomLevel); double tiley_exact = lat2tiley(topleft.latitude(), zoomLevel); int x_start = (int)floor(tilex_exact); int y_start = (int)floor(tiley_exact); int x_end = (int)floor(tilex_exact) + width / TILE_DIMENSION + 1; int y_end = (int)floor(tiley_exact) + height / TILE_DIMENSION + 1; QQueue<Tile> list; for (int y = y_start; y <= y_end; y++) { for (int x = x_start; x <= x_end; x++) { Tile info; info.x = x * TILE_DIMENSION; info.y = y * TILE_DIMENSION; info.w = TILE_DIMENSION; info.h = TILE_DIMENSION; info.zoom = zoomLevel; list.enqueue(info); } } startDownload(list); }
static void calculatePeripheralPoints(QList<QGeoCoordinate> &path, const QGeoCoordinate ¢er, qreal distance, int steps) { // Calculate points based on great-circle distance // Calculation is the same as GeoCoordinate's atDistanceAndAzimuth function // but tweaked here for computing multiple points // pre-calculate qreal latRad = qgeocoordinate_degToRad(center.latitude()); qreal lonRad = qgeocoordinate_degToRad(center.longitude()); qreal cosLatRad = std::cos(latRad); qreal sinLatRad = std::sin(latRad); qreal ratio = (distance / (qgeocoordinate_EARTH_MEAN_RADIUS * 1000.0)); qreal cosRatio = std::cos(ratio); qreal sinRatio = std::sin(ratio); qreal sinLatRad_x_cosRatio = sinLatRad * cosRatio; qreal cosLatRad_x_sinRatio = cosLatRad * sinRatio; for (int i = 0; i < steps; ++i) { qreal azimuthRad = 2 * M_PI * i / steps; qreal resultLatRad = std::asin(sinLatRad_x_cosRatio + cosLatRad_x_sinRatio * std::cos(azimuthRad)); qreal resultLonRad = lonRad + std::atan2(std::sin(azimuthRad) * cosLatRad_x_sinRatio, cosRatio - sinLatRad * std::sin(resultLatRad)); qreal lat2 = qgeocoordinate_radToDeg(resultLatRad); qreal lon2 = qgeocoordinate_radToDeg(resultLonRad); if (lon2 < -180.0) { lon2 += 360.0; } else if (lon2 > 180.0) { lon2 -= 360.0; } path << QGeoCoordinate(lat2, lon2, center.altitude()); } }
static bool addAtForBoundingArea(const QGeoShape &area, QUrlQuery *queryItems) { QGeoCoordinate center; switch (area.type()) { case QGeoShape::RectangleType: center = QGeoRectangle(area).center(); break; case QGeoShape::CircleType: center = QGeoCircle(area).center(); break; case QGeoShape::UnknownType: break; } if (!center.isValid()) { return false; } else { queryItems->addQueryItem(QLatin1String("at"), QString::number(center.latitude()) + QLatin1Char(',') + QString::number(center.longitude())); return true; } }
/*! \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. }
/*! Sets the height of this geo rectangle in degrees to \a degreesHeight. If \a degreesHeight is less than 0.0 or if this geo rectangle is invalid this function does nothing. To set up the values of an invalid geo rectangle based on the center, width and height you should use setCenter() first in order to make the geo rectangle valid. If the change in height would cause the geo rectangle to cross a pole the height is adjusted such that the geo rectangle only touches the pole. This change is done such that the center coordinate is still at the center of the geo rectangle, which may result in a geo rectangle with a smaller height than might otherwise be expected. If \a degreesHeight is greater than 180.0 then 180.0 is used as the height. */ void QGeoRectangle::setHeight(double degreesHeight) { if (!isValid()) return; if (degreesHeight < 0.0) return; if (degreesHeight >= 180.0) { degreesHeight = 180.0; } Q_D(QGeoRectangle); double tlLon = d->topLeft.longitude(); double brLon = d->bottomRight.longitude(); QGeoCoordinate c = center(); double tlLat = c.latitude() + degreesHeight / 2.0; double brLat = c.latitude() - degreesHeight / 2.0; if (tlLat > 90.0) { brLat = 2* c.latitude() - 90.0; tlLat = 90.0; } if (tlLat < -90.0) { brLat = -90.0; tlLat = -90.0; } if (brLat > 90.0) { tlLat = 90.0; brLat = 90.0; } if (brLat < -90.0) { tlLat = 2 * c.latitude() + 90.0; brLat = -90.0; } d->topLeft = QGeoCoordinate(tlLat, tlLon); d->bottomRight = QGeoCoordinate(brLat, brLon); }
void GpsPosition::timeout() { double distance = 0; qDebug() << "\ntimeout\n\n"; QGeoCoordinate coord = _location->lastKnownPosition(true).coordinate(); qDebug() << "SAVED POSITION lat = " << _latitude << " lon = " << _longitude; qDebug() << "LAST POSITION lat = " << coord.latitude() << " lon = " << coord.longitude(); if (coord.isValid()){ distance = Core::DatabaseSqlite::calculate_distance(_latitude, _longitude, coord.latitude(), coord.longitude()); qDebug() << "distancd = " << distance; /* check distance between the last and found coordinates */ if (distance > UPDATE_DISTANCE){ /* distance more then UPDATE_DISTANCE km */ emit findCoord(coord.latitude(), coord.longitude()); } } }
void MapBox::captureCoordinates() { QGeoCoordinate coords = m_mapWidget->screenPositionToCoordinate(m_lastClicked); if (!coords.isValid()) return; m_latitudeEdit->setText(QString::number(coords.latitude())); m_longitudeEdit->setText(QString::number(coords.longitude())); }
void QDeclarativeCoordinate::setCoordinate(const QGeoCoordinate &coordinate) { QGeoCoordinate previousCoordinate = m_coordinate; m_coordinate = coordinate; // Comparing two NotANumbers is false which is not wanted here if (coordinate.altitude() != previousCoordinate.altitude() && !(qIsNaN(coordinate.altitude()) && qIsNaN(previousCoordinate.altitude()))) { emit altitudeChanged(m_coordinate.altitude()); } if (coordinate.latitude() != previousCoordinate.latitude() && !(qIsNaN(coordinate.latitude()) && qIsNaN(previousCoordinate.latitude()))) { emit latitudeChanged(m_coordinate.latitude()); } if (coordinate.longitude() != previousCoordinate.longitude() && !(qIsNaN(coordinate.longitude()) && qIsNaN(previousCoordinate.longitude()))) { emit longitudeChanged(m_coordinate.longitude()); } }
QPoint GeoMap::coordinateToOffscreenPosition (QGeoCoordinate coordinate) { QPoint pixelPosition; QGeoCoordinate originCoordinate = screenPositionToCoordinate(QPointF(0,0)); QGeoCoordinate differenceFromOrigin = QGeoCoordinate (originCoordinate.latitude() - coordinate.latitude(), coordinate.longitude() - originCoordinate.longitude()); pixelPosition = QPoint(differenceFromOrigin.longitude() * pixelsPerDegreeLongitude, differenceFromOrigin.latitude() * pixelsPerDegreeLatitude); return pixelPosition; }
/*! \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(); } }
/*! \internal */ void QDeclarativeGeoMapGestureArea::startOneTouchPoint() { sceneStartPoint1_ = touchPoints_.at(0).scenePos(); lastPos_ = sceneStartPoint1_; lastPosTime_.start(); QGeoCoordinate startCoord = map_->screenPositionToCoordinate(QDoubleVector2D(sceneStartPoint1_), false); // ensures a smooth transition for panning startCoord_.setLongitude(startCoord_.longitude() + startCoord.longitude() - touchCenterCoord_.longitude()); startCoord_.setLatitude(startCoord_.latitude() + startCoord.latitude() - touchCenterCoord_.latitude()); }
/*! \internal */ void QDeclarativeGeoMapGestureArea::startTwoTouchPoints() { sceneStartPoint1_ = touchPoints_.at(0).scenePos(); sceneStartPoint2_ = touchPoints_.at(1).scenePos(); QPointF startPos = (sceneStartPoint1_ + sceneStartPoint2_) * 0.5; lastPos_ = startPos; lastPosTime_.start(); QGeoCoordinate startCoord = map_->screenPositionToCoordinate(QDoubleVector2D(startPos), false); startCoord_.setLongitude(startCoord_.longitude() + startCoord.longitude() - touchCenterCoord_.longitude()); startCoord_.setLatitude(startCoord_.latitude() + startCoord.latitude() - touchCenterCoord_.latitude()); }
/*! \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. }
QT_BEGIN_NAMESPACE QDoubleVector2D QGeoProjection::coordToMercator(const QGeoCoordinate &coord) { const double pi = M_PI; double lon = coord.longitude() / 360.0 + 0.5; double lat = coord.latitude(); lat = 0.5 - (std::log(std::tan((pi / 4.0) + (pi / 2.0) * lat / 180.0)) / pi) / 2.0; lat = qBound(0.0, lat, 1.0); return QDoubleVector2D(lon, lat); }
void QGeoTiledMapPolylineObjectInfo::genPath() { QPainterPath p; QList<QGeoCoordinate> path = polyline->path(); if (path.size() > 0) { QGeoCoordinate origin = path.at(0); double ox = origin.longitude() * 3600.0; double oy = origin.latitude() * 3600.0; double oldx = ox; double oldy = oy; p.moveTo(0, 0); for (int i = 1; i < path.size(); ++i) { QGeoCoordinate pt = path.at(i); double x = pt.longitude() * 3600.0; double y = pt.latitude() * 3600.0; if (qAbs(x - oldx) > 180.0 * 3600.0) { if (x > oldx) { x -= 360.0 * 3600.0; } else if (x < oldx) { x += 360.0 * 3600.0; } } p.lineTo(x - ox, y - oy); oldx = x; oldy = y; } } pathItem->setPath(p); }
void GeoHelper::searchFinishedSlot(QGeoSearchReply *reply) { if (reply->error() == QGeoSearchReply::NoError) { QScriptEngine scriptEngine; QScriptValue replyObject = scriptEngine.newArray(); QList<QGeoPlace> places = reply->places(); for (int i = 0; i < places.count(); i++) { QScriptValue placeObject = scriptEngine.newObject(); QScriptValue coordinateObject = scriptEngine.newObject(); QGeoCoordinate coordinate = places[i].coordinate(); coordinateObject.setProperty("latitude", QScriptValue(coordinate.latitude())); coordinateObject.setProperty("longitude", QScriptValue(coordinate.longitude())); placeObject.setProperty("coordinate", coordinateObject); QScriptValue addressObject = scriptEngine.newObject(); QGeoAddress address = places[i].address(); if (!address.isEmpty()) { addressObject.setProperty("country", address.country()); addressObject.setProperty("countryCode", address.countryCode()); addressObject.setProperty("state", address.state()); addressObject.setProperty("county", address.county()); addressObject.setProperty("city", address.city()); addressObject.setProperty("district", address.district()); addressObject.setProperty("street", address.street()); addressObject.setProperty("postcode", address.postcode()); } placeObject.setProperty("address", addressObject); replyObject.setProperty(i, placeObject); } QScriptValue fun = scriptEngine.evaluate("(function(a) { return JSON.stringify(a); })"); QScriptValueList args; args << replyObject; QScriptValue result = fun.call(QScriptValue(), args); emit searchReply(result.toString()); } }
void debug_data() { QTest::addColumn<QGeoCoordinate>("c"); QTest::addColumn<QByteArray>("debugString"); QTest::newRow("uninitialized") << QGeoCoordinate() << QByteArray("QGeoCoordinate(?, ?)"); QTest::newRow("initialized without altitude") << BRISBANE << (QString("QGeoCoordinate(%1, %2)").arg(BRISBANE.latitude()) .arg(BRISBANE.longitude())).toLatin1(); QTest::newRow("invalid initialization") << QGeoCoordinate(-100,-200) << QByteArray("QGeoCoordinate(?, ?)"); QTest::newRow("initialized with altitude") << QGeoCoordinate(1,2,3) << QByteArray("QGeoCoordinate(1, 2, 3)"); }