
首先登陆腾讯位置服务网站https://lbs.qq.com/
登陆后创建一个应用

勾选webserviceapi
并填写自己的微信小程序授权appid
提交后等待审核,审核通过后,就可以看到key了

wxml
<map id="map" style="width:100%;height:500px;" show-location="true" circles="{{circles}}" longitude="{{longitude}}" markers="{{markers}}" polyline="{{polyline}}" latitude="{{latitude}}" scale="14" ></map>js代码var coors;官方的webserviceapi接口文档地址:https://lbs.qq.com/service/webService/webServiceGuide/webServiceRoute
Page({
data: {
longitude: 116.75498,
latitude: 23.37228,
polyline: [],
markers: [
{
latitude: 23.362490,
longitude: 116.715790,
iconPath: "/images/my_marker.png", //图标路径
},
{
latitude: 23.37228,
longitude: 116.75498,
iconPath: "/images/my_marker.png", //图标路径
},
],
},
onLoad: function (options) {
var that = this;
wx.request({
url: 'https://apis.map.qq.com/ws/direction/v1/driving/?from=23.362490,116.715790&to=23.37228,116.75498&output=json&callback=cb&key=申请的key'
,
success: function (res) {
coors = res.data.result.routes[0].polyline
for (var i = 2; i < coors.length; i++) {
coors[i] = coors[i - 2] + coors[i] / 1000000
}
console.log(coors)
//划线
var b = [];
for (var i = 0; i < coors.length; i = i + 2) {
b[i / 2] = {
latitude: coors[i],
longitude: coors[i + 1]
};
console.log(b[i / 2])
}
let markers=that.data.markers;
markers.push( {
latitude: 23.373390,
longitude: 116.716590,
iconPath: "/images/no.png", //图标路径
width:340,
height:40,
label:{
content:"共"+ res.data.result.routes[0].distance/1000+"公里,大约需要"+res.data.result.routes[0].duration+"分钟",
bgColor:"#ff9000",
padding:"9px 20px",
alpha:1,
borderRadius:"50rpx",
display:"ALWAYS",
color:"#ffffff",
fontsize:14
}
}
);
console.log(markers);
that.setData({
markers:markers,
polyline: [{
points: b,
color: "#a52a2a",
width: 4,
dottedLine: false
}],
})
}
})
},
});
项目源码下载地址:map.zip
网友回复
seedream5.5为啥无法将图白色背景修改成透明?
seedance2如何通过2张不同角度平视图来识别场景进行人物定位?
有没有免费的浏览器中离线运行的语音识别ai模型?
微信小程序个人版不交钱认证就不让你用二维码,报错"errcode":85411?
美丽国为啥要限制ai发展?
seedance2如何参考白模视频使用真实场景和人物生成新视频?
如何设定小孩看电视的时候每隔10分钟弹出一个题目,答对才能继续,答错继续下一题?
直播数字人根据公屏互动评论实时做出不用动作技术是什么?
未来ai文本大模型根据剧本直接生成像素风或三维白模或灰模粗糙场景动画html给视频大模型参考站位与运镜?
浏览器中如何将epub电子书转成txt文本格式?


