小程序获取经纬度百度地图逆地址解析

首先呢我们要实现的功能是小程序调用 wx.getLocation api去拿用户的经纬度,拿到经纬度在调用百度接口解析地址

现在给大家演示:

bmap-wx.min.js 去官方文档下载即可  http://lbsyun.baidu.com/index.php?title=wxjsapi

//index.js
//获取应用实例
const app = getApp()
const bmap = require('../../../utils/bmap-wx.min.js');
Page({
    data: {
        wxMarkerData:[]
        longitude: '',   //经度  
        latitude: '',    //纬度  
    },
    onLoad(){
        var that = this;
        var BMap = new bmap.BMapWX({
            ak: '百度地图申请的ak'
        });

        wx.getLocation({
            type: 'wgs84',
            success: function (res) {
               
                that.setData({
                    latitude: res.latitude,//经度
                    longitude: res.longitude//纬度
                })
                console.log(res,'经纬度')
                BMap.regeocoding({
                    location: that.data.latitude + ',' + that.data.longitude,
                    success: function (res) {
                        console.log(res)
                       
                        that.setData({
                            wxMarkerData : res.wxMarkerData //地址信息
                        })
                    },
                    fail: function () {
                        wx.showToast({
                            title: '请检查位置服务是否开启',
                        })
                    },
                });
            },
            fail: function () {
                console.log('小程序得到坐标失败')
            }
        })
        
       
    }
})

 

喜欢上方小程序,需要源码的,私信小编留下邮箱。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端_李嘉豪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值