为啥没人看看呢,搞一天了,求帮忙啊
发布于 6 年前 作者 xiulancai 15935 次浏览 来自 问答

js:


onLoad: function () {

// 获取位置

var that = this;

// 实例化腾讯地图API核心类

qqmapsdk = new QQMapWX({

key: 'PKYBZ-EB4RQ-KBF5P-GMINL-C6FXK-FHBNI' // 必填

});

wx.getLocation({

type'wgs84',

success: function (res) {

that.setData({

latitude:res.latitude,

longitude:res.longitude

})

//2、根据坐标获取当前位置名称,显示在顶部:腾讯地图逆地址解析

qqmapsdk.reverseGeocoder({

location: {

latitude: res.latitude,

longitude: res.longitude

},

success: function (e) {

var location = e.result.address;

console.log("add="+location)

为什么这一段不会打印

that.setData({

location: location

})

}

})

// console.log("res==" + app.globalData.latitude)

// console.log("res==" + app.globalData.longitude)

that.setData({

ldata: true,

// latitude: latitude,

// longitude: longitude

})

},

fail: function (res) {

console.log('拒绝授权')

that.setData({

ldata: false

})

}

})

},

btnTap(e) {

console.log("e+" + this.data.latitude + "," + this.data.longitude)

wx.openLocation({


latitude: this.data.latitude,

longitude: this.data.longitude,

scale: 50

})

},

wxml:

<button wx:if="{{ldata}}" bindtap='btnTap' plain='true' type="primary" size="{{mini}}" loading="{{loading}}"

plain="{{plain}}" disabled="{{disabled}}">查看当前位置</button>

<button wx:else open-type="openSetting" bindopensetting='handler' plain='true' type="primary"

size="{{mini}}" loading="{{loading}}"

plain="{{plain}}" disabled="{{disabled}}">点击授权并获取位置信息</button>

看着网上的例子写的,也看了文档,不知道哪里出了问题,没有效果

3 回复

腾讯地图api获取并且注册相关小程序key没问题情况下,确保正确引入sdk,success不进的话, 去fail看一下error

大哥,您的这个问题解决了没,我也弄了一天了,request合法域名配置了 https://apis.map.qq.com ,在微信开发者工具上可以通过经纬度使用qqmapsdk.reverseGeocoder()获取到位置信息,在手机上打开调试模式也可以,但是一关调试模式就不行了。。。。卡了一天了,求大哥支援。。。。。小弟感激不尽。。。。。

没用过 没法帮你~

回到顶部