小程序
小游戏
企业微信
微信支付
扫描小程序码分享
- 当前 Bug 的表现(可附上截图)
真机上获取不到当前的位置,我把wx.getLocation添加到onLoad:function中的,然后在map组件中加了个显示当前位置标志,当前位置是显示出来的,但实际位置有偏移,就一直定位到那个位置,从来没有动过
- 预期表现
- 复现路径
- 提供一个最简复现 Demo
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
可以提供一下简单的代码片段吗
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
markertap: function(e) { //点击地图上的标记点时画出路线let that2 = this;var markerID = e.markerId; //获取当前点击markers数组里的经纬度// console.log(markerID)var Markerng = that2.data.markers[markerID-1].callout.content;console.log(Markerng)var endlat = that2.data.markers[markerID - 1].latitude;var endlog = that2.data.markers[markerID - 1].longitudevar fromlat = that2.data.latvar fromlog = that2.data.logvar disvar durthat2.setData({MarkerNeirong: Markerng})wx.request({url: 'https://apis.map.qq.com/ws/direction/v1/walking/?from=' + fromlat + ',' + fromlog + '&to=' + endlat + ',' + endlog + '&output=json&callback=cb&key=' + qqMapKey,success: function (res) {coors = res.data.result.routes[0].polyline// console.log(res)dis = res.data.result.routes[0].distancedur = res.data.result.routes[0].durationfor (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])}that2.setData({polyline: [{points: b,color: "#99FF00",width: 4,dottedLine: false}],distance: dis,duration: dur},)}})}, onLoad: function() { var that = this;wx.getLocation({success: function(res) {var latitude = res.latitudevar longtitude = res.longitudeconsole.log(latitude,longtitude)that.setData({lat: latitude,log: longtitude})},})}
markertap: function(e) { //点击地图上的标记点时画出路线
let that2 = this;
var markerID = e.markerId; //获取当前点击markers数组里的经纬度
// console.log(markerID)
var Markerng = that2.data.markers[markerID-1].callout.content;
console.log(Markerng)
var endlat = that2.data.markers[markerID - 1].latitude;
var endlog = that2.data.markers[markerID - 1].longitude
var fromlat = that2.data.lat
var fromlog = that2.data.log
var dis
var dur
that2.setData({
MarkerNeirong: Markerng
})
wx.request({
url: 'https://apis.map.qq.com/ws/direction/v1/walking/?from=' + fromlat + ',' + fromlog + '&to=' + endlat + ',' + endlog + '&output=json&callback=cb&key=' + qqMapKey,
success: function (res) {
coors = res.data.result.routes[0].polyline
// console.log(res)
dis = res.data.result.routes[0].distance
dur = res.data.result.routes[0].duration
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])
polyline: [{
points: b,
color: "#99FF00",
width: 4,
dottedLine: false
}],
distance: dis,
duration: dur
},
)
onLoad: function() {
var that = this;
wx.getLocation({
success: function(res) {
var latitude = res.latitude
var longtitude = res.longitude
console.log(latitude,longtitude)
that.setData({
lat: latitude,
log: longtitude
关键是前几天还能用的,这两天就不能用了。
有没有大神帮我看看是怎么回事啊
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
可以提供一下简单的代码片段吗
关键是前几天还能用的,这两天就不能用了。
有没有大神帮我看看是怎么回事啊