zoukankan      html  css  js  c++  java
  • 小程序之当前地址获取

    在小程序中获取地理位置信息的流程就是:

    1.根据wx.getLocation方法获取当前位置坐标。

    2.根据reverseGeocoder方法获取当前坐标地理位置信息。 

    具体实现如下:

    //1.1引入sdk核心类(写在app.js中,其他页面用到直接引用)
    var
    QQMapWX = require('/utils/qqmap-wx-jssdk.min.js'); //app.js App({ onLaunch: function () { var that = this;
         //1.2实例化腾讯地图API核心类 that.globalData.qqmapsdk
    = new QQMapWX({ key: '开发秘钥' });      //1.3wx.getLocation方法获取当前位置坐标。 wx.getLocation({ altitude:false, success: function (res) { var latitude = res.latitude; var longitude = res.longitude; that.globalData.location={ latitude: latitude, longitude: longitude } } }); }, globalData: { url: '' } })

    说明:根据wx.getLocation方法获取当前位置坐标。这个是写在app.js中,某个页面用的时候在某页面的js文件中根据qqmapsdk.reverseGeocoder方法获取当前坐标地理位置信息。 

    onLoad: function (options) {
    
            var that = this;
    
    
            app.globalData.qqmapsdk.reverseGeocoder({       //qqmapsdk.reverseGeocoder
    
                location: {
                    latitude: app.globalData.location.latitude,
                    longitude: app.globalData.location.longitude
                },
                success: function (res) {
    
                    var address = res.result.address;
    
                    that.setData({
    
                        current_address: address
    
                    });
    
                },
                fail: function (res) {
    
                    wx.showToast({
                        title: '解析地址错误',
                        icon: 'loading',
                        duration: 1000
                    });
    
                },
    
            })
    
    
        }
     
  • 相关阅读:
    JS 位数不够自动左补0
    oracle 不同表空间的数据迁移
    Vue 学习
    c# 之Web.config
    c# 之泛型
    WritableWorkbook操作Excel
    MIME类型
    Excel 批量出来数据
    Excel的用到的常规的技巧
    得到Xml中 元素的值
  • 原文地址:https://www.cnblogs.com/wanan-01/p/9040247.html
Copyright © 2011-2022 走看看