微信小程序获取附近商家

**

源代码-微信小程序获取附近商家

**

const app = getApp();
var timer = false;
var QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
var qqmapsdk;
Page({
  data: {
    statusBarHeight: app.globalData.statusBarHeight,
    page: 1,
    pois: [],
    result: [],
    latitude: '',
    longitude: ''
  },
  
  onLoad: function () {
    qqmapsdk = new QQMapWX({
        key: '秘钥'
    })
  },
  onShow: function () {
    let vm = this;
    vm.getUserLocation();
  },
  // 授权位置信息
  getUserLocation: function () {
    let vm = this;
    wx.getSetting({
      success: (res) => {
        if (res.authSetting['scope.userLocation'] != undefined &&
         res.authSetting['scope.userLocation'] != true) {
          wx.showModal({
            title: '请求授权当前位置',
            content: '需要获取您的地理位置,请确认授权',
            success: function (res) {
              if (res.cancel) {
                wx.showToast({
                  title: '拒绝授权',
                  icon: 'none',
                  duration: 1000
                })
              } else if (res.confirm) {
                wx.openSetting({
                  success: function (dataAu) {
                    if (dataAu.authSetting["scope.userLocation"]  =  true) {
                      wx.showToast({
                        title: '授权成功',
                        icon: 'success',
                        duration: 1000
                      })
                      //再次授权,调用wx.getLocation的API
                      vm.getLocation();
                    } else {
                      wx.showToast({
                        title: '授权失败',
                        icon: 'none',
                        duration: 1000
                      })
                    }
                  }
                })
              }
            }
          })
        } else if (res.authSetting['scope.userLocation'] == undefined) {
          //调用wx.getLocation的API
          vm.getLocation();
        }
        else {
          //调用wx.getLocation的API
          vm.getLocation();
        }
      }
    })
  },
  // 微信获得经纬度
  getLocation: function () {
    let vm = this;
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        console.log('获得经纬度:',JSON.stringify(res))
        var latitude = res.latitude
        var longitude = res.longitude
        vm.setData({
          latitude: latitude,
          longitude: longitude
        })
        vm.getLocal(latitude, longitude)
      },
      fail: function (res) {
      }
    })
  },
  // 获取当前地理位置
  getLocal: function (latitude, longitude) {
    let that = this;
    wx.showLoading({
      title: '加载中',
      duration: 3000
    })
    qqmapsdk.reverseGeocoder({
      location: {
        latitude: latitude,
        longitude: longitude,
      },
      success:function (params) {
        console.log('params',params)
        that.setData({
          result:params.result
        })
      }
    }),
    qqmapsdk.search({
      location: {
        latitude: latitude,
        longitude: longitude,
      },
      keyword:'小吃',
      page_size:10,
      page_index:that.data.page,
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log('地理位置:',res);
        wx.hideLoading()
        let pois = res.data
        that.setData({
          pois: that.data.pois.concat(pois),
        })
      },
      fail: function (res) {
        console.log(res);
      },
      complete: function (res) {
        // console.log(res);
      }
    });

  },

  // 点击进入地图
  turn_map:function (e) {
    console.log('e',e)
    wx.openLocation({
      latitude: e.currentTarget.dataset.index.lat,
      longitude: e.currentTarget.dataset.index.lng,
      scale: 18,
      name:e.currentTarget.dataset.name,
      address:e.currentTarget.dataset.address,
    })
    console.log('e',e)
  },
  // 下拉获取数据页数
  onReachBottom:function(){
    let vm = this;
    vm.setData({
      page:vm.data.page+1
    })
    vm.getLocal(vm.data.latitude, vm.data.longitude)
  }
  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
适合专科和本科毕业生的【原创论文】【已降重】【万字】【本科】【专科】【毕业论文】【预览目录】【预览正文】 适合专科和本科毕业生的【原创论文】【已降重】【万字】【本科】【专科】【毕业论文】【预览目录】【预览正文】 适合专科和本科毕业生的【原创论文】【已降重】【万字】【本科】【专科】【毕业论文】【预览目录】【预览正文】 适合专科和本科毕业生的【原创论文】【已降重】【万字】【本科】【专科】【毕业论文】【预览目录】【预览正文】 适合专科和本科毕业生的【原创论文】【已降重】【万字】【本科】【专科】【毕业论文】【预览目录】【预览正文】适合专科和本科毕业生的【原创论文】【已降重】【万字】【本科】【专科】【毕业论文】【预览目录】【预览正文】 适合专科和本科毕业生的【原创论文】【已降重】【万字】【本科】【专科】【毕业论文】【预览目录】【预览正文】适合专科和本科毕业生的【原创论文】【已降重】【万字】【本科】【专科】【毕业论文】【预览目录】【预览正文】适合专科和本科毕业生的【原创论文】【已降重】【万字】【本科】【专科】【毕业论文】【预览目录】【预览正文】适合专科和本科毕业生的【原创论文】【已降重】【万字】【本科】【专科】【毕业论文】【预览目录】【预览正文】适合专科和本科毕业生的【原创论文】【已降重】【万字】【本科】【专科】【毕业论文】【预览目录】【预览正文】

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值