地图无法定位

来源:2-2 首页地图页的实现(下)

weixin_慕函数5570425

2021-05-08 16:35:55

问题描述:

当点击定位图标的时候 并不会跳到所处位置 真机调试也尝试过 一直显示正在定位


相关截图(点击定位后的效果):

http://img.mukewang.com/climg/60964d6109beac5e31281858.jpg

相关代码:

index.ts

Page({
data: {
setting: {
skew: 0,
rotate: 0,
showLocation: true,
showScale: true,
subKey: '',
layerStyle: -1,
enableZoom: true,
enableScroll: true,
enableRotate: true,
showCampass: true,
enable3D: false,
enableOverlooking: false,
enableSatelitte: false,
enableTraffic: false,
},
location: {
latitude: 31.254569,
longitude: 121.504774,
},
scale: 10,
markers: [
{
iconPath: "/resources/car.png",
id: 0,
latitude: 31.254187,
longitude: 121.502281,
width: 50,
height: 50
},
]
},
onMyLocationTap () {
wx.getLocation({
type: 'gcj02',
success: res => {
this.setData({
location: {
latitude: res.latitude,
longitude: res.longitude,
}
})
}
})
}
})

index.wxml

<map
id="map"
lattitude="{{location.latitude}}"
longitude="{{location.longitude}}"
scale="{{scale}}"
setting="{{setting}}"
enable-overlooking="{{isOverLooking}}"
enable-3D="{{is3D}}"
markers="{{markers}}"
>
<cover-view class="icon-container">
<cover-image src="/resources/account.png"></cover-image>
<cover-image
src="/resources/my_location.png"
bindtap="onMyLocationTap"
>
</cover-image>
</cover-view>
</map>


写回答

1回答

ccmouse

2021-05-15

不能的话主要采用真机调试。

可以打印一下getLocation中的success函数回调的参数。在getLocation中还考虑加入fail回调函数看一下是否有错。

另外,打开微信自己的发送位置等功能,看看是否能够定位。

1

0 学习 · 1399 问题

查看课程