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

    通过微信自己的接口API,用户授权后获取到经纬度,通过经纬度调用地图接口返回地理位置信息。

    简单、明了!!!(网上自己查询的文档进行编程,转载请注明出处)

    代码如下:

    qqMapApi: 'http://apis.map.qq.com/ws/geocoder/v1/', //地图接口链接
     
    //获取经纬度
    getPosition() {
    let that = this;
    wx.getLocation({
    type: 'wgs84',
    success: function(res) {
    var latitude = res.latitude;
    var longitude = res.longitude;
    // wx.setStorageSync('latitude', latitude) //纬度
    // wx.setStorageSync('longitude', longitude) //经度
    var qqMapApi = that.qqMapApi + "?location=" + latitude + ',' +
    longitude + "&key=" + 'XVLBZ-BSU66-ULJSQ-MFGXD-TM7GZ-55F2M' + "&get_poi=1";
    wx.request({
    url: qqMapApi,
    data: {},
    method: 'GET',
    success: (res) => {
    console.log(res)
    if (res.statusCode == 200 && res.data.status == 0) {
    that.country = res.data.result.address_component.nation;
    that.province = res.data.result.address_component.province;
    that.city = res.data.result.address_component.city;
    that.county = res.data.result.address_component.district;
    that.street = res.data.result.address_component.street;
    }
    }
    })
    },
    fail() {
    that.fn_fail();
    }
    })

    },
  • 相关阅读:
    DNS隧道
    记录上锁(fcntl)
    posix对线程的调整
    MySQL创建存储过程
    MySQL的WHERE语句中BETWEEN与IN的用法和他们的区别
    mysql中distinct
    线程的工作方式-流水线
    可执行程序的生成过程
    线程高级编程
    time函数及其用法
  • 原文地址:https://www.cnblogs.com/zhangjiabin/p/8276400.html
Copyright © 2011-2022 走看看