如何在Ubuntu手机中利用百度地图显示一个坐标位置

发布网友 发布时间: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接口进行显示地图信息.
在上面的代码中,我们显示两个图片,一个是没有经过转换的图片,另外一个是经过坐标转换后的地图图片.经过比对,我们会发现,经过转换过的地图信息更贴近我们的实际的位置.

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com