uniapp为实现打卡功能,需要获取用户当前的地理位置,所以在此做开发记录,仅供参考
先引入高德地图小程序api文件,具体下载地址https://lbs.amap.com/api/wx/guide/create-project/config-project
在项目需要的的页面引入,通过uniapp提供的uni.getLocation()方法获取地理位置,开启高精度定位,传入高德地图获取详细地理信息。
var amapFile = require('@/common/utils/amap-wx.130.js');
//----------------
initMap() {
let location = ''
uni.getLocation({
type: 'gcj02',
altitude: true,
highAccuracyExpireTime: 5000,
success: function (res) {
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
location = `${res.longitude},${res.latitude}`
}
});
const self = this
var myAmapFun = new amapFile.AMapWX({key:'xxxxxxxxxxxxxxxxxxxxxxx'}); // 平台申请的key
myAmapFun.getRegeo({
location: location