uniapp定位获取当前地址
文章描述:
uniapp安卓定位获取当前地址
高德地图
申请key
服务平台:微信小程序
小程序SDK
网址:https://lbs.amap.com/api/wx/download
代码:
template
<template>
<view>
<view @click="getRegeo">获取当前定位...</view>
<view>地址:{{addressName}}</view>
</view>
</template>
script
/* 高德微信小程序版sdk */
import amap from '../../components/amap-wx/amap-wx.130.js';
export default {
data() {
return {
amapPlugin: null,
key: '638bf750623f176707c52d150415a388',
addressName: ''
}
},
onLoad() {
this.amapPlugin = new amap.AMapWX({
key: this.key
})
this.getRegeo();
},
methods: {
getRegeo() {
const _this = this;
uni.showLoading({
title: '获取信息中'
});
_this.amapPlugin.getRegeo({
success: (data) => {
console.log(data, '当前定位')
_this.addressName = data[0].name;
uni.hideLoading();
},
file: (err) => {
console.log(err)
}
});
}
}
}
发布时间:2021/12/06
发表评论