微信小程序获取地理位置

news/2024/7/20 3:00:16 标签: 微信小程序, 小程序

首先微信公众平台开通权限

app.json

 "permission":{
    "scope.userLocation": {
      "desc": "您的位置信息将用于获取周围门店信息"
    }
  },
  "requiredPrivateInfos": [
		"getLocation"
	],
 "sitemapLocation": "sitemap.json",

index.js

 onLoad: function () {
this.getLocation()
},
 getLocation() {
   
    console.log('pppp')
    var that = this;
    wx.getLocation({
      type: 'wgs84',
      success (res) {
        console.log(res)
        const latitude = res.latitude
        const longitude = res.longitude
        const speed = res.speed
        const accuracy = res.accuracy
        console.log(res) //将获取到的经纬度信息输出到控制台以便检查
     

        that.setData({ //将获取到的经度、纬度数值分别赋值给本地变量
          latitude: res.latitude,
          longitude: res.longitude,
          location:res.latitude+','+res.longitude
        })
        console.log(res.latitude+','+res.longitude)
        wx.setStorageSync('location', res.latitude+','+res.longitude)//arr是要存的数据
        
      },
      fail(err){
        console.log(err);
      }
     })
  },


http://www.niftyadmin.cn/n/1367263.html

相关文章

uniapp(小程序)背景水印和原生html实现

uniapp ​ <!-- 水印 --> <template> <view classwater_top><canvas canvas-idwatermarkCanvas stylewidth:100%;height:100%></canvas> </view> </template> <script>export default {data() {return {}},onLoad() {console…

vue实现无限下级修改名称(递归)

<el-form-item label"部门"><el-cascader style"width:100%" v-model"inneraccount.deptId" :options"department" change"handleChange"></el-cascader></el-form-item> // 部门getDepartmentTree…

uniapp中uni.navigateBack();传参

// B页面let pages getCurrentPages();let prevPage pages[pages.length - 2]; //上一个页面this.lablelist.forEach(el > {if (el.seclect) {object.push(el)}})prevPage.$vm.getParams(object); //重点$vmuni.navigateBack();// A页面 methods: { getParams(object) {co…

【键盘/支付】h5键盘以及拉起微信/支付宝支付功能

这里写自定义目录标题<div class"container" id"newsInfoPreview" v-cloak><!-- 输入框 以及商户信息&#xff0c;这里从后台拿数据获取对应的商户信息--><div class"monenyBox"><div class"logoBox"><div…

vue生成海报

vue生成海报 1、引入插件 npm install qrcodejs2 --save npm install html2canvas --save//在需要的地方引入 import VueQrcode from xkeshi/vue-qrcode import html2canvas from html2canvas;2、html海报中背景图片&#xff0c;这里用的是本地路径&#xff0c;如果是用线上路…

【vue下载base64格式的图片】

1、创建downLoad.js文件 class Download {//引用调用的方法&#xff0c;传入文件名称和bas64格式的文件downloadFile(fileName, content) {let aLink document.createElement(a);let blob this.base64ToBlob(content); //new Blob([content]);let evt document.createEvent…

axios无痛刷新

vue axios请求新的token&#xff0c;无痛刷新 import {serialize} from /util/util import {getStore} from ../util/store import NProgress from nprogress // progress bar import errorCode from /const/errorCode import router from /router/router import {Message} fr…

【vue知识点】

1、this.$set() (Vue.set()) 在vue中直接给一个数组项赋值&#xff0c;vue并不能检测到变化 //在vue中给对象数组项赋值&#xff0c;没办法赋值&#xff0c;vue渲染不出来this.dataForm.arr1 [1,2]//用$set给对象的数组项赋值&#xff0c;则能渲染出来this.$set(this.dataForm,…