收藏
回答

微信公众号调用功微信wx.getLocation定位 经常走到fail: 刷新页面就可以了?

const getLocationChange = async () => {
  console.log('加载定位');
  wx.ready(() => {
    setTimeout(() => {
      wx.getLocation({
        type: 'gcj02', // 返回火星坐标(腾讯地图使用)
        success: async (res) => {
          console.log('定位ok');
          let resAdd = {
            latitude: res.latitude,
            longitude: res.longitude
          };
          localStorage.setItem('coordinate', JSON.stringify(resAdd));
          await getStore();
        },
        fail: function(err) {
          console.error('定位失败:', err);
          Dialog.alert({
            title: '提示',
            message: '获取位置信息失败,请刷新',
            confirmButtonText: '刷新'
          }).then(() => {
            // 刷新当前页面
            location.reload();
          });
        }
      });
    }, 1000);
  });
};


回答关注问题邀请回答
收藏

3 个回答

登录 后发表内容