收藏
回答

小程序定位只能拿到经纬度吗?可以拿到地理信息不?

我想拿到当前定位经纬度和地址描述

除了经纬度还需要 xxx路xx号 或者 xxx小区南门 或者xxx地铁站

怎么拿到详细信息呢?只能服务端用api解析吗?

回答关注问题邀请回答
收藏

4 个回答

  • L.
    L.
    03-04

    用腾讯地图的逆地址解析

    https://https://lbs.qq.com/miniProgram/jsSdk/jsSdkGuide/methodReverseGeocoder

    使用案例:

    var QQMapWX = require('../../static/js/qqmap-wx-jssdk.min');
    var qqmapsdk;
    
    
    Page({
    
    
        onLoadfunction () {
            // 实例化API核心类
            qqmapsdk = new QQMapWX({
                key'申请的key'
            });
    
    
        },
        onShowfunction () {
            let that = this
            wx.getLocation({
                type"gcj02",
                success(res) {
                    that.reverseGeocoder(res.latitude,res.longitude)
                },
                fail(err) {
                    console.log(11111111);
                    wx.hideLoading();
                    wx.showToast({
                        title'定位失败',
                        icon'none',
                        duration1500
                    })
                    self.setData({
                        lastPagefalse,
                        isRefreshingfalse
                    })
                }
            })
        },
        reverseGeocoder(lat, lng) {
            let that = this
            qqmapsdk.reverseGeocoder({
                location: {
                    latitude: lat,
                    longitude: lng
                },
                successfunction (res//成功后的回调
                    console.log('reverseGeocoder:', res);
                    that.setData({
                        
                    })
                },
                failfunction (error{
                    console.error(error);
                },
                completefunction (res{
                    console.log(res);
                }
            })
        },
    })
    


    03-04
    有用 1
    回复
  • 小黎
    小黎
    03-04

    是的,只能通过拿到的经纬度进行逆地址解析

    03-04
    有用 1
    回复
  • 那一抹微笑😊穿透阳光
    那一抹微笑😊穿透阳光
    03-04

    只能获取经纬度,想要位置信息,只有你自己通过腾讯api等转换

    03-04
    有用 1
    回复
  • 智能回答 智能回答 该问答由AI生成
    03-04
    有用
登录 后发表内容