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 98bb661 commit 871672e
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 84 deletions.
13 changes: 11 additions & 2 deletions android/src/com/x/MyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ public class MyActivity
private long movingTime;
private float totalDistance = 0f;
private float maxSpeed = 0f;
private float mySpeed = 0f;
private float totalClimb = 0f;
private Location previousLocation;
private double previousAltitude;
Expand Down Expand Up @@ -770,6 +771,7 @@ public double startGpsUpdates() {
startTime = System.currentTimeMillis();
totalDistance = 0f;
maxSpeed = 0f;
mySpeed = 0f;
totalClimb = 0f;
previousLocation = null;
movingTime = 0;
Expand Down Expand Up @@ -843,6 +845,12 @@ public double getTotalDistance() {

}

public double getMySpeed() {

return mySpeed;

}

public double getLatitude() {

return latitude;
Expand Down Expand Up @@ -886,8 +894,9 @@ private void updateTrackingData(Location currentLocation) {
totalDistance += previousLocation.distanceTo(currentLocation) / 1000; // 转换为公里

// 计算最大速度
if (currentLocation.getSpeed() * 3.6f > maxSpeed) {
maxSpeed = currentLocation.getSpeed() * 3.6f; // 转换为 km/h
mySpeed = currentLocation.getSpeed() * 3.6f;// 转换为 km/h
if (mySpeed > maxSpeed) {
maxSpeed = mySpeed;
}

// 计算爬升
Expand Down
1 change: 1 addition & 0 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3422,6 +3422,7 @@ void MainWindow::initQW() {
ui->qwGpsList->setSource(
QUrl(QStringLiteral("qrc:/src/qmlsrc/gps_list.qml")));
ui->qwGpsList->rootContext()->setContextProperty("myW", this->width());
ui->qwGpsList->rootContext()->setContextProperty("m_Steps", m_Steps);

ui->qwMap->setSource(QUrl(QStringLiteral("qrc:/src/qmlsrc/map.qml")));
ui->qwMap->rootContext()->setContextProperty("isGpsRun", false);
Expand Down
63 changes: 55 additions & 8 deletions src/Steps/Steps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,16 @@ void Steps::startRecordMotion() {

if (m_time.second() % 3) {
if (!isGpsTest) {
if (m_distance > 0) {
appendTrack(latitude, longitude);
nWriteGpsCount++;
writeGpsPos(latitude, longitude, nWriteGpsCount, nWriteGpsCount);
jdouble m_speed = m_activity.callMethod<jdouble>("getMySpeed", "()D");
mySpeed = m_speed;
if (m_distance > 0 & mySpeed > 0) {
if (latitude + longitude != oldLat + oldLon) {
appendTrack(latitude, longitude);
nWriteGpsCount++;
writeGpsPos(latitude, longitude, nWriteGpsCount, nWriteGpsCount);
oldLat = latitude;
oldLon = longitude;
}
}
} else {
appendTrack(latitude, longitude);
Expand All @@ -444,7 +450,8 @@ void Steps::startRecordMotion() {

mw_one->ui->qwMap->rootContext()->setContextProperty("strDistance",
str1);
mw_one->ui->qwMap->rootContext()->setContextProperty("strSpeed", str3);
mw_one->ui->qwMap->rootContext()->setContextProperty(
"strSpeed", QString::number(mySpeed) + " km/h");
}
}

Expand Down Expand Up @@ -564,7 +571,7 @@ void Steps::stopRecordMotion() {
t4 = tr("Average Speed") + ": " + str3;
t5 = str6;

if (m_distance > 0) {
if (m_distance > 0 || isGpsTest) {
int nYear = QDate::currentDate().year();
int nMonth = QDate::currentDate().month();
QString strTitle = QString::number(nYear) + " - " + QString::number(nMonth);
Expand Down Expand Up @@ -784,8 +791,10 @@ void Steps::clearTrack() {
}

void Steps::writeGpsPos(double lat, double lon, int i, int count) {
QString s0 = t0.replace(" ", "");
QString s1 = strStartTime.replace(":", "");
QString ss0 = t0;
QString s0 = ss0.replace(" ", "");
QString sst = strStartTime;
QString s1 = sst.replace(":", "");

QSettings Reg(iniDir + s0 + "-gps-" + s1 + ".ini", QSettings::IniFormat);
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
Expand All @@ -795,3 +804,41 @@ void Steps::writeGpsPos(double lat, double lon, int i, int count) {
Reg.setValue("/" + QString::number(i) + "/lon", lon);
Reg.setValue("/count", count);
}

void Steps::getGpsTrack() {
QQuickItem* root = mw_one->ui->qwGpsList->rootObject();
QVariant itemCount;
QMetaObject::invokeMethod((QObject*)root, "getTimeString",
Q_RETURN_ARG(QVariant, itemCount));
QString mStr = itemCount.toString();
QStringList list = mStr.split("-=-");
QString st1 = list.at(0);
QString st2 = list.at(1);
st1 = st1.replace(" ", "");
st2 = st2.split("-").at(0);
QStringList list2 = st2.split(":");
st2 = list2.at(1) + list2.at(2) + list2.at(3);
st1 = st1.trimmed();
st2 = st2.trimmed();

QString gpsFile = iniDir + st1 + "-gps-" + st2 + ".ini";
if (QFile::exists(gpsFile)) {
QSettings Reg(gpsFile, QSettings::IniFormat);
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
Reg.setIniCodec("utf-8");
#endif

clearTrack();
int count = Reg.value("/count", 0).toInt();
for (int i = 0; i < count; i++) {
double lat =
Reg.value("/" + QString::number(i + 1) + "/lat", 0).toDouble();
double lon =
Reg.value("/" + QString::number(i + 1) + "/lon", 0).toDouble();
appendTrack(lat, lon);
}
mw_one->ui->tabMotion->setCurrentIndex(3);
} else {
qDebug() << "gps file=" + gpsFile + " no exists.";
}
}
4 changes: 4 additions & 0 deletions src/Steps/Steps.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Steps : public QDialog {
void appendTrack(double lat, double lon);
public slots:
void clearAllGpsList();
void getGpsTrack();
private slots:
void positionUpdated(const QGeoPositionInfo &info);

Expand All @@ -101,6 +102,8 @@ class Steps : public QDialog {
QString strDurationTime;
double latitude = 59.91;
double longitude = 10.75;
double oldLat;
double oldLon;
QString strGpsStatus;
QString strGpsInfoShow;
QString lblStyle;
Expand All @@ -122,6 +125,7 @@ class Steps : public QDialog {
void writeGpsPos(double lat, double lon, int i, int count);
int nWriteGpsCount;
bool isGpsTest = false;
double mySpeed;
signals:
void distanceChanged(double distance);
void timeChanged();
Expand Down
90 changes: 25 additions & 65 deletions src/qmlsrc/gps_list.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ Rectangle {

property int itemCount: 0
property bool isHighPriority: false
property string strGpsTime: ""

function setItemHeight(h) {}

function getTimeString() {
return strGpsTime
}

function gotoEnd() {
view.positionViewAtEnd()
}
Expand Down Expand Up @@ -153,7 +158,7 @@ Rectangle {
Rectangle {
id: listItem
width: ListView.view.width
height: getItemHeight() + 16
height: getItemHeight() + 16 + btnViewGpsTrack.height

// color: ListView.isCurrentItem ? "lightblue" : getColor()
// border.width: isDark ? 0 : 1
Expand Down Expand Up @@ -349,10 +354,26 @@ Rectangle {

visible: item5.text.length ? true : false
}

Button {
id: btnViewGpsTrack
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("View GPS Track")
width: parent.width
height: 35

enabled: true

onClicked: {
strGpsTime = item0.text + "-=-" + item1.text
m_Steps.getGpsTrack()
}
}
}
}

MouseArea {

/*MouseArea {
property point clickPos: "0,0"
Expand All @@ -361,16 +382,7 @@ Rectangle {
clickPos = Qt.point(mouse.x, mouse.y)
}
onReleased: {
var delta = Qt.point(mouse.x - clickPos.x,
mouse.y - clickPos.y)
console.debug("delta.x: " + delta.x)
if ((delta.x < 0) && (aBtnShow.running === false)
&& (delBtn.width == 0)) {
aBtnShow.start()
} else if (aBtnHide.running === false
&& (delBtn.width > 0)) {
aBtnHide.start()
}
}
onClicked: {
Expand All @@ -385,59 +397,7 @@ Rectangle {
//var data = view.model.get(view.currentIndex)
//console.log(data.text0 + "," + data.type + ", count=" + view.count)
}
}

Rectangle {
color: "#AAAAAA"
height: 0
width: parent.width
anchors.bottom: parent.bottom
}

Rectangle {
id: delBtn
visible: false
height: parent.height
width: 0
color: "#FF0000"

anchors.right: parent.right
anchors.rightMargin: -30
radius: 0

Text {
width: 56
anchors.centerIn: parent

text: qsTr("Done")
color: "#ffffff"
}

MouseArea {
anchors.fill: parent
onClicked: {
m_Todo.addToRecycle()
view.model.remove(index)
}
}
}

PropertyAnimation {
id: aBtnShow
target: delBtn
property: "width"
duration: 100
from: 0
to: 80
}
PropertyAnimation {
id: aBtnHide
target: delBtn
property: "width"
duration: 100
from: 80
to: 0
}
}*/
}
}

Expand Down
20 changes: 11 additions & 9 deletions src/qmlsrc/map.qml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Window 2.15
import QtLocation 5.15
import QtPositioning 5.15
Expand All @@ -19,17 +20,16 @@ Rectangle {
var newCoordinate = QtPositioning.coordinate(lat, lon)

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


let pathArray = polyline.path

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

map.center = newCoordinate
}

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

Plugin {
Expand All @@ -48,18 +48,20 @@ Rectangle {
id: polyline
line.color: "red"
line.width: 3
//path: [QtPositioning.coordinate(59.91,

// test
// path: [QtPositioning.coordinate(59.91,
// 10.75),
// QtPositioning.coordinate(
// gpsx+0.0000, gpsy+0.0000)//QtPositioning.coordinate(59.912, 10.752)
// ]
// 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
anchorPoint.x: markerImage.width / 2 + 6
anchorPoint.y: markerImage.height / 2
sourceItem: Image {
id: markerImage
source: "/res/marker.png" // 替换为你的标记图标
Expand Down

0 comments on commit 871672e

Please sign in to comment.