Skip to content

Commit

Permalink
map
Browse files Browse the repository at this point in the history
  • Loading branch information
ic005k committed Feb 18, 2025
1 parent ff5e585 commit 98bb661
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 40 deletions.
2 changes: 2 additions & 0 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3425,6 +3425,8 @@ void MainWindow::initQW() {

ui->qwMap->setSource(QUrl(QStringLiteral("qrc:/src/qmlsrc/map.qml")));
ui->qwMap->rootContext()->setContextProperty("isGpsRun", false);
ui->qwMap->rootContext()->setContextProperty("strDistance", "0 km");
ui->qwMap->rootContext()->setContextProperty("strSpeed", "0 km/h");

ui->qwReport->rootContext()->setContextProperty("m_Report", m_Report);
ui->qwReport->setSource(QUrl(QStringLiteral("qrc:/src/qmlsrc/report.qml")));
Expand Down
49 changes: 38 additions & 11 deletions src/Steps/Steps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,10 @@ void Steps::startRecordMotion() {
m_activity.callMethod<jdouble>("getTotalDistance", "()D");
QString str_distance = QString::number(distance, 'f', 2);
m_distance = str_distance.toDouble();
latitude = m_activity.callMethod<jdouble>("getLatitude", "()D");
longitude = m_activity.callMethod<jdouble>("getLongitude", "()D");
if (!isGpsTest) {
latitude = m_activity.callMethod<jdouble>("getLatitude", "()D");
longitude = m_activity.callMethod<jdouble>("getLongitude", "()D");
}
QAndroidJniObject jstrGpsStatus =
m_activity.callObjectMethod<jstring>("getGpsStatus");
if (jstrGpsStatus.isValid()) {
Expand All @@ -425,20 +427,43 @@ void Steps::startRecordMotion() {
strGpsStatus = str4 + "\n" + str5 + "\n" + str6 + "\n" + str7;
}

if (m_time.second() % 3 && m_distance > 0) {
appendTrack(latitude, longitude);
nWriteGpsCount++;
writeGpsPos(latitude, longitude, nWriteGpsCount, nWriteGpsCount);
if (m_time.second() % 3) {
if (!isGpsTest) {
if (m_distance > 0) {
appendTrack(latitude, longitude);
nWriteGpsCount++;
writeGpsPos(latitude, longitude, nWriteGpsCount, nWriteGpsCount);
}
} else {
appendTrack(latitude, longitude);
latitude = latitude + 0.001;
longitude = longitude + 0.001;
nWriteGpsCount++;
writeGpsPos(latitude, longitude, nWriteGpsCount, nWriteGpsCount);
}

mw_one->ui->qwMap->rootContext()->setContextProperty("strDistance",
str1);
mw_one->ui->qwMap->rootContext()->setContextProperty("strSpeed", str3);
}
mw_one->ui->qwMap->rootContext()->setContextProperty("strDistance", str1);
mw_one->ui->qwMap->rootContext()->setContextProperty("strSpeed", str3);
}

#else
if (m_time.second() != 0) {
m_speed = m_distance / m_time.second();
emit speedChanged();
}

if (isGpsTest) {
if (m_time.second() % 3) {
appendTrack(latitude, longitude);
latitude = latitude + 0.001;
longitude = longitude + 0.001;
nWriteGpsCount++;
writeGpsPos(latitude, longitude, nWriteGpsCount, nWriteGpsCount);
}
}

#endif

strTotalDistance = QString::number(m_TotalDistance) + " km";
Expand Down Expand Up @@ -507,8 +532,10 @@ void Steps::positionUpdated(const QGeoPositionInfo& info) {
}
lastPosition = info.coordinate();

latitude = lastPosition.latitude();
longitude = lastPosition.longitude();
if (!isGpsTest) {
latitude = lastPosition.latitude();
longitude = lastPosition.longitude();
}
}

void Steps::stopRecordMotion() {
Expand Down Expand Up @@ -760,7 +787,7 @@ void Steps::writeGpsPos(double lat, double lon, int i, int count) {
QString s0 = t0.replace(" ", "");
QString s1 = strStartTime.replace(":", "");

QSettings Reg(iniDir + s0 + "-gps-" + s1, QSettings::IniFormat);
QSettings Reg(iniDir + s0 + "-gps-" + s1 + ".ini", QSettings::IniFormat);
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
Reg.setIniCodec("utf-8");
#endif
Expand Down
5 changes: 3 additions & 2 deletions src/Steps/Steps.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ class Steps : public QDialog {
QTimer *timer;
QString strTotalDistance;
QString strDurationTime;
double latitude;
double longitude;
double latitude = 59.91;
double longitude = 10.75;
QString strGpsStatus;
QString strGpsInfoShow;
QString lblStyle;
Expand All @@ -121,6 +121,7 @@ class Steps : public QDialog {
void clearTrack();
void writeGpsPos(double lat, double lon, int i, int count);
int nWriteGpsCount;
bool isGpsTest = false;
signals:
void distanceChanged(double distance);
void timeChanged();
Expand Down
62 changes: 35 additions & 27 deletions src/qmlsrc/map.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,27 @@ Rectangle {
height: 600

// 变量定义
property double gpsx: 51.5074
property double gpsy: -0.1278
property double gpsx: 59.91
property double gpsy: 10.75

//property string strSpeed: "0.00"
// property string strDistance: "0.00"
function appendTrack(lat, lon) {

// trajectory.path.push({
// "latitude": lat,
// "longitude": lon
// })
var newPath = [{
"latitude": lat,
"longitude": lon
} // London
// Paris
]
trajectory.path = newPath // 使用新的路径更新
gpsx = lat
gpsy = lon
map.center = QtPositioning.coordinate(gpsx, gpsy)

var newCoordinate = QtPositioning.coordinate(lat, lon)

//polyline.path.push([newCoordinate])


let pathArray = polyline.path

pathArray.push(newCoordinate); // 添加新的点
polyline.path = pathArray

map.center = newCoordinate
}

function clearTrack() {
trajectory.path = []
function clearTrack() {polyline.path = []
}

Plugin {
Expand All @@ -46,18 +42,30 @@ Rectangle {
anchors.fill: parent
plugin: mapPlugin
center: QtPositioning.coordinate(gpsx, gpsy) // 初始中心坐标(伦敦)
zoomLevel: 14
zoomLevel: 13

MapPolyline {
id: trajectory
id: polyline
line.color: "red"
line.width: 3
path: [// 初始轨迹点
QtPositioning.coordinate(51.5074,
-0.1278), QtPositioning.coordinate(
51.5080, -0.1280), QtPositioning.coordinate(
51.507, -0.1279), QtPositioning.coordinate(51.5089,
-0.1289)]
//path: [QtPositioning.coordinate(59.91,
// 10.75),
// QtPositioning.coordinate(
// gpsx+0.0000, gpsy+0.0000)//QtPositioning.coordinate(59.912, 10.752)
// ]
}

// 可选:添加一个标记来表示当前位置
MapQuickItem {
coordinate: QtPositioning.coordinate(gpsx, gpsy)
anchorPoint.x: markerImage.width/2+6
anchorPoint.y: markerImage.height/2
sourceItem: Image {
id: markerImage
source: "/res/marker.png" // 替换为你的标记图标
width: 32
height: 32
}
}
}

Expand Down

0 comments on commit 98bb661

Please sign in to comment.