【小程序位置解析】,经纬度获取具体位置 qqmapsdk.reverseGeocoder

jiexi(num) {
			var that = this
			qqmapsdk.reverseGeocoder({
				location: {
					latitude:that.latitude,
					longitude: that.longitude
				},
				success: function(res) { //成功后的回调
					console.log(res,'解析');
					let params = {
						longitude: that.longitude,
						latitude:  that.latitude,
						location: res.result.address_component.street+res.result.address_reference.landmark_l2.title
					}
			
					that.$http.post('punch', params).then(res => {
						if (res.err_code == 0) {
							that.show = true
							setTimeout(()=>{
								that.show = false
							}, 2000)
							
						}
					});
				},
				fail: function(error) {
					console.error(error, '解析fail');
				},
				complete: function(res) {
					console.log(res,'complete');
				}
			})
		},
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在微信小程序中,可以使用腾讯地图提供的 `map` 组件来展示地图,并且可以通过 `wx.getLocation` 方法获取当前位置经纬度坐标。然后,将这些经纬度坐标传递给 `qqmapsdk.reverseGeocoder` 方法来获取当前位置的详细地址信息。 为了将地图中心点设置为当前位置,可以在 `map` 组件上绑定 `bindregionchange` 事件,当地图视野变化时触发该事件。在 `bindregionchange` 事件回调函数中,可以通过 `e` 参数获取当前地图的中心点坐标 `e.caenterLatitude` 和 `e.centerLongitude`,并将其传递给 `qqmapsdk.reverseGeocoder` 方法来获取当前中心点的详细地址信息。 以下是示例代码: ```javascript // 在页面中引入腾讯地图 SDK var qqmapsdk = new QQMapWX({ key: 'yourKey' }); Page({ onReady: function () { // 获取当前位置经纬度坐标 wx.getLocation({ type: 'gcj02', success: function (res) { var latitude = res.latitude; var longitude = res.longitude; // 将经纬度坐标传递给 qqmapsdk.reverseGeocoder 方法获取详细地址信息 qqmapsdk.reverseGeocoder({ location: { latitude: latitude, longitude: longitude }, success: function (res) { console.log(res.result.address); } }); // 设置地图中心点为当前位置 this.mapCtx = wx.createMapContext('myMap'); this.mapCtx.moveToLocation(); } }) }, // 监听地图视野变化事件 bindregionchange: function (e) { // 获取当前地图中心点的经纬度坐标 var latitude = e.caenterLatitude; var longitude = e.centerLongitude; // 将经纬度坐标传递给 qqmapsdk.reverseGeocoder 方法获取详细地址信息 qqmapsdk.reverseGeocoder({ location: { latitude: latitude, longitude: longitude }, success: function (res) { console.log(res.result.address); } }); } }) ``` 在上述示例代码中,`yourKey` 需要替换为您自己的腾讯地图开发者密钥,`myMap` 需要替换为您在页面中使用 `map` 组件的 `id` 属性值。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值