checklist() {
const that = this
uni.showLoading({
title: '正在获取打卡位置'
})
uni.getLocation({
type: 'gcj02',
geocode: true, //设置该参数为true可直接获取经纬度及城市信息
success: function(res) {
that.addrDel = res;
that.area =
res.address.country +
res.address.province +
res.address.city +
res.address.district +
res.address.street +
res.address.streetNum +
res.address.poiName,
uni.hideLoading();
console.log(that.addrDel, '我在这');
},
fail: function(e) {
uni.showToast({
// title: ${JSON.stringify(e)}
title: '获取 位置失败'
});
},
});
},
- 发布:2023-05-29 13:56
- 更新:2023-05-29 14:04
- 阅读:320
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win11
HBuilderX类型: 正式
HBuilderX版本号: 3.8.3
手机系统: iOS
手机系统版本号: iOS 16
手机厂商: 苹果
手机机型: 苹果11
页面类型: vue
vue版本: vue2
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
操作步骤:
checklist() {
const that = this
uni.showLoading({
title: '正在获取打卡位置'
})
uni.getLocation({
type: 'gcj02',
geocode: true, //设置该参数为true可直接获取经纬度及城市信息
success: function(res) {
that.addrDel = res;
that.area =
res.address.country +
res.address.province +
res.address.city +
res.address.district +
res.address.street +
res.address.streetNum +
res.address.poiName,
uni.hideLoading();
console.log(that.addrDel, '我在这');
},
fail: function(e) {
uni.showToast({
// title: ${JSON.stringify(e)}
title: '获取 位置失败'
});
},
});
},
checklist() {
const that = this
uni.showLoading({
title: '正在获取打卡位置'
})
uni.getLocation({
type: 'gcj02',
geocode: true, //设置该参数为true可直接获取经纬度及城市信息
success: function(res) {
that.addrDel = res;
that.area =
res.address.country +
res.address.province +
res.address.city +
res.address.district +
res.address.street +
res.address.streetNum +
res.address.poiName,
uni.hideLoading();
console.log(that.addrDel, '我在这');
},
fail: function(e) {
uni.showToast({
// title: ${JSON.stringify(e)}
title: '获取 位置失败'
});
},
});
},
预期结果:
checklist() {
const that = this
uni.showLoading({
title: '正在获取打卡位置'
})
uni.getLocation({
type: 'gcj02',
geocode: true, //设置该参数为true可直接获取经纬度及城市信息
success: function(res) {
that.addrDel = res;
that.area =
res.address.country +
res.address.province +
res.address.city +
res.address.district +
res.address.street +
res.address.streetNum +
res.address.poiName,
uni.hideLoading();
console.log(that.addrDel, '我在这');
},
fail: function(e) {
uni.showToast({
// title: ${JSON.stringify(e)}
title: '获取 位置失败'
});
},
});
},
checklist() {
const that = this
uni.showLoading({
title: '正在获取打卡位置'
})
uni.getLocation({
type: 'gcj02',
geocode: true, //设置该参数为true可直接获取经纬度及城市信息
success: function(res) {
that.addrDel = res;
that.area =
res.address.country +
res.address.province +
res.address.city +
res.address.district +
res.address.street +
res.address.streetNum +
res.address.poiName,
uni.hideLoading();
console.log(that.addrDel, '我在这');
},
fail: function(e) {
uni.showToast({
// title: ${JSON.stringify(e)}
title: '获取 位置失败'
});
},
});
},
实际结果:
checklist() {
const that = this
uni.showLoading({
title: '正在获取打卡位置'
})
uni.getLocation({
type: 'gcj02',
geocode: true, //设置该参数为true可直接获取经纬度及城市信息
success: function(res) {
that.addrDel = res;
that.area =
res.address.country +
res.address.province +
res.address.city +
res.address.district +
res.address.street +
res.address.streetNum +
res.address.poiName,
uni.hideLoading();
console.log(that.addrDel, '我在这');
},
fail: function(e) {
uni.showToast({
// title: ${JSON.stringify(e)}
title: '获取 位置失败'
});
},
});
},
checklist() {
const that = this
uni.showLoading({
title: '正在获取打卡位置'
})
uni.getLocation({
type: 'gcj02',
geocode: true, //设置该参数为true可直接获取经纬度及城市信息
success: function(res) {
that.addrDel = res;
that.area =
res.address.country +
res.address.province +
res.address.city +
res.address.district +
res.address.street +
res.address.streetNum +
res.address.poiName,
uni.hideLoading();
console.log(that.addrDel, '我在这');
},
fail: function(e) {
uni.showToast({
// title: ${JSON.stringify(e)}
title: '获取 位置失败'
});
},
});
},
bug描述:
打包后,uni.getLocation安卓能正常拿到城市信息,ios则无反应
DCloud_iOS_WZT
iOS 系统定位不会反地理编码 需要集成高德或者百度才可以
2023-05-29 15:10