zoukankan      html  css  js  c++  java
  • 微信小程序 获取地理位置信息

    app.json

    "permission":{
      "scope.userLocation": {
        "desc": "你的位置信息将用于小程序位置接口的效果展示"
      }
    },

    index.js

    onLoad: function (options) {
        this.getLocationDetail();
      },
    
      getLocationDetail () {
        wx.getLocation({
          type: 'wgs84',
          success: res => {
            const latitude = res.latitude
            const longitude = res.longitude
            console.log("lat:" + latitude + ",lon:" + longitude)
            this.getCity(latitude, longitude);
          },
          fail: function (res) { },
          complete: function (res) { },
        })
      },
      getCity (latitude, longitude) {
        wx.request({
            url: "http://api.map.baidu.com/reverse_geocoding/v3/",
            data: {
              ak: "你的ak密钥百度随便申请",
              output: "json",
              location: latitude + "," + longitude
            },
          success: res => {
            console.log(res)
          },
        })
      },

  • 相关阅读:
    expect
    grep
    Python函数
    Python的set
    Python字典
    Python循环
    Python条件判断
    Python列表
    Python字符串
    Python组织代码块的形式
  • 原文地址:https://www.cnblogs.com/CyLee/p/11901232.html
Copyright © 2011-2022 走看看