发布网友 发布时间:2022-04-22 11:12
共1个回答
热心网友 时间:2023-10-12 03:17
Main.qml
[html] view plain copy
import QtQuick 2.4
import Ubuntu.Components 1.3
import "WebApi.js" as API
import QtPositioning 5.0
MainView {
id: mainScreen
// objectName for functional testing purposes (autopilot-qt5)
objectName: "mainView"
// Note! applicationName needs to match the "name" field of the click manifest
applicationName: "map.liu-xiao-guo"
property string longitude: "116.3883"
property string latitude: "39.92"
width: units.gu(60)
height: units.gu(85)
PositionSource {
id: me
active: true
updateInterval: 1000
preferredPositioningMethods: PositionSource.AllPositioningMethods
onPositionChanged: {
console.log("latitude: " + position.coordinate.latitude + " longitude: " +
position.coordinate.longitude);
console.log(position.coordinate)
mainScreen.longitude = position.coordinate.longitude;
mainScreen.latitude = position.coordinate.latitude;
before.source = API.getStaticMap(longitude, latitude)
// Do the conversion here
API.convertCoordinates(longitude, latitude, gotConverted)
}
onSourceErrorChanged: {
console.log("Source error: " + sourceError);
}
}
function gotConverted(o) {
after.source = API.getStaticMap(o.longitude, o.latitude)
}
Page {
title: i18n.tr("map")
Column {
anchors.fill: parent
spacing: units.gu(2)
Image {
id: before
width: parent.width
height: parent.height/2
Label {
text: "Before conversion"
fontSize: "large"
}
}
Image {
id: after
width: parent.width
height: parent.height/2
Label {
text: "After conversion"
fontSize: "large"
}
}
}
}
}
在上面的代码中,我们使用:
[html] view plain copy
PositionSource {
id: me
active: true
updateInterval: 1000
preferredPositioningMethods: PositionSource.AllPositioningMethods
onPositionChanged: {
console.log("latitude: " + position.coordinate.latitude + " longitude: " +
position.coordinate.longitude);
console.log(position.coordinate)
mainScreen.longitude = position.coordinate.longitude;
mainScreen.latitude = position.coordinate.latitude;
before.source = API.getStaticMap(longitude, latitude)
// Do the conversion here
API.convertCoordinates(longitude, latitude, gotConverted)
}
onSourceErrorChanged: {
console.log("Source error: " + sourceError);
}
}
来得到我们的当前的位置信息:经度,维度.我们可以通过百度的staticmap API接口进行显示地图信息.
在上面的代码中,我们显示两个图片,一个是没有经过转换的图片,另外一个是经过坐标转换后的地图图片.经过比对,我们会发现,经过转换过的地图信息更贴近我们的实际的位置.