详见:码云小程序demo1
1.注册腾讯地图>设置key>key管理勾选WebServiceAPI
2.开发文档>服务端WebServiceAPI>逆地址解析(坐标位置描述)
//获取get请求的接口,location和key必填
3.wxml
<van-cell-group>
{{address}}
<!-- autosize:自适应 -->
<van-field autosize type="textarea"
model:value="{{ address }}" center clearable label="短信验证码"
placeholder="请输入短信验证码"
border="{{ false }}" use-button-slot>
<van-button custom-style="width:100rpx" slot="button"
size="small" type="primary" icon="location-o"
bindtap="getAddress3"></van-button>
</van-field>
</van-cell-group>
3.js
import Router from '../../utils/index'
import {
getLocationWithSetting
} from '../../utils/location'
Router({
/**
* 页面的初始数据
*/
data: {
address: '',
},
async getAddress3() { //转化成同步 执行函数getLocationWithSetting,并打印
let res = await getLocationWithSetting()
console.log(res);
if (res) {
let address = await this.$get('https://apis.map.qq.com/ws/geocoder/v1/', {
//将经纬度转化成 例:39.984154,116.307490的格式
location: [res.lat, res.lng].join(),
key: 'K2VBZ-IM5WO-V65W7-SV4SA-W4HYF-VSFD3'
}
//打印地址
this.$set('address', address.result.address +
address.result.formatted_addresses.recommend)
}
},
}
定位3.根据经纬度在获取的腾讯地图接口上找到地址
最新推荐文章于 2022-10-14 10:59:38 发布