let _this = this
uni.getLocation({
type: 'wgs84',
geocode: true, //设置该参数为true可直接获取经纬度及城市信息
success: function(res) {
console.log('获取定位信息', res);
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
_this.mss = res
// _this.cityName = res.address.city
// _this.getco()
// 创建地图坐标对象
var point = new plus.maps.Point(res.longitude, res.latitude);
console.log(point,'反编')
//静态方法,反向地理编码
plus.maps.Map.reverseGeocode(point, {}, (event) => {
console.log('99999999')
var address = event.address; // 转换后的地理位置
var point = event.coord; // 转换后的坐标信息
var coordType = event.coordType; // 转换后的坐标系类型
var reg = /.+?(省|市|自治区|自治州|县|区)/g;
var addressList = address.match(reg).toString().split(",");
console.log("addressList",address.match(reg));
},
function(e) {
console.log("失败回调", e);
}
);
console.log("addressList", _this.addressList)
},
fail: function(err) {
console.log("获取定位失败", err);
uni.showToast({
title: '获取定位失败',
icon: 'none'
});
}
5***@qq.com
- 发布:2021-12-30 23:37
- 更新:2022-01-01 14:59
- 阅读:563
1 个回复
FullStack - 【插件开发】【专治疑难杂症】【ios上架、马甲包、白包、过审、已成功上架过几百个】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=22130】【非诚勿扰】QQ:543610866
参考链接:https://uniapp.dcloud.io/api/location/location?id=getlocation