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()) ); }
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; } }
/*! 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 longitude() { QFETCH(double, value); QGeoCoordinate c; c.setLongitude(value); QCOMPARE(c.longitude(), value); QGeoCoordinate c2 = c; QCOMPARE(c.longitude(), value); QCOMPARE(c2, c); }
static bool crossEarthPole(const QGeoCoordinate ¢er, qreal distance) { qreal poleLat = 90; QGeoCoordinate northPole = QGeoCoordinate(poleLat, center.longitude()); QGeoCoordinate southPole = QGeoCoordinate(-poleLat, center.longitude()); // approximate using great circle distance qreal distanceToNorthPole = center.distanceTo(northPole); qreal distanceToSouthPole = center.distanceTo(southPole); if (distanceToNorthPole < distance || distanceToSouthPole < distance) return true; return false; }
/*! 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 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 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 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(); } }
/*! \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. }
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()); }
/*! Sets the width of this geo rectangle in degrees to \a degreesWidth. If \a degreesWidth 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 \a degreesWidth is greater than 360.0 then 360.0 is used as the width, the leftmost longitude of the geo rectangle is set to -180.0 degrees and the rightmost longitude of the geo rectangle is set to 180.0 degrees. */ void QGeoRectangle::setWidth(double degreesWidth) { if (!isValid()) return; if (degreesWidth < 0.0) return; Q_D(QGeoRectangle); if (degreesWidth >= 360.0) { d->topLeft.setLongitude(-180.0); d->bottomRight.setLongitude(180.0); return; } double tlLat = d->topLeft.latitude(); double brLat = d->bottomRight.latitude(); QGeoCoordinate c = center(); double tlLon = c.longitude() - degreesWidth / 2.0; if (tlLon < -180.0) tlLon += 360.0; if (tlLon > 180.0) tlLon -= 360.0; double brLon = c.longitude() + degreesWidth / 2.0; if (brLon < -180.0) brLon += 360.0; if (brLon > 180.0) brLon -= 360.0; d->topLeft = QGeoCoordinate(tlLat, tlLon); d->bottomRight = QGeoCoordinate(brLat, brLon); }
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)"); }
/*! \internal */ void QDeclarativeGeoMapGestureArea::panStateMachine() { PanState lastState = panState_; // Transitions switch (panState_) { case panInactive: if (canStartPan()) { // Update startCoord_ to ensure smooth start for panning when going over startDragDistance QGeoCoordinate newStartCoord = map_->screenPositionToCoordinate(QDoubleVector2D(lastPos_), false); startCoord_.setLongitude(newStartCoord.longitude()); startCoord_.setLatitude(newStartCoord.latitude()); panState_ = panActive; } break; case panActive: if (touchPoints_.count() == 0) { panState_ = panFlick; if (!tryStartFlick()) { panState_ = panInactive; // mark as inactive for use by camera if (pinchState_ == pinchInactive) emit movementStopped(); } } break; case panFlick: if (touchPoints_.count() > 0) { // re touched before movement ended endFlick(); panState_ = panActive; } break; } // Update switch (panState_) { case panInactive: // do nothing break; case panActive: updatePan(); // this ensures 'panStarted' occurs after the pan has actually started if (lastState != panActive) emit panStarted(); break; case panFlick: break; } }