uniapp 微信小程序获取map地图中心的经纬度地理位置

在页面上放置一个map组件

<map id="mapId" ref="mapId" style="width: 750rpx; height:calc(100vh - 120rpx);" 
			:latitude="latitude" :longitude="longitude" :markers="markers" @regionchange="onRegionChange">

函数编写

			//获取中心点位置
			getCenterLatLong(){
                let mapObjs = uni.createMapContext('mapId', this) // 得到map实例对象
                mapObjs.getCenterLocation({
                      success: res=>{
                          console.log('p000:',res)
                   
                      },
                      fail: res=>{
                          console.log('p1111:',res)
          
                      },
                      complete: res=>{
                          console.log('p222:',res)

                      }
                    })
            },

函数调用

        // 地图移动时触发
        onRegionChange(e){
			if (e.type === 'end') { //在安卓中是 end 事件
				this.getCenterLatLong()  // 地图移动时获取中心点的经纬度
			}else if(e.type ==='regionchange'){ // 在ios中是 regionchange
				this.getCenterLatLong() 
			}
        },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值