2***@qq.com
2***@qq.com
  • 发布:2024-01-24 16:39
  • 更新:2024-01-24 16:39
  • 阅读:219

uni.getLoaction在第一次请求权限时点击禁止,重新请求仍会请求获取权限

分类:uni-app

onLoad(option) {
this.getAddress()
}

getAddress() {
let self = this;
uni.getLocation({
type: 'gcj02',
geocode: true,
success: function(res) {

                    var point = new plus.maps.Point(res.longitude, res.latitude);  

                    plus.maps.Map.reverseGeocode(point, {}, (event) => {  

                            var address = event.address; // 转换后的地理位置  
                            var point = event.coord; // 转换后的坐标信息  
                            var coordType = event.coordType; // 转换后的坐标系类型  
                            var reg = /.+?(省|市|自治区|自治州|县|区)/g;  
                            var addressList = address.match(reg).toString().split(",");  
                            //注意 因为存在直辖市, 当所在地区为普通省市时,addressList.length == 3,city = addressList[1];当所在地区为直辖市时addressList.length == 2,city = addressList[0];  
                            // let city = addressList.length == 3 ? addressList[1] : addressList[0];  
                            if (addressList.length == 2) {  
                                self.citys = addressList[0] + addressList[1];  
                                self.cityFlag = addressList[0];  

                            } else if (addressList.length == 3) {  
                                self.citys = addressList[1] + addressList[2];  
                                self.cityFlag = addressList[1];  

                            } else if (addressList.length == 4) {  
                                self.citys = addressList[1] + addressList[2];  
                                self.cityFlag = addressList[1];  

                            } else {  
                                self.citys = addressList[1] + addressList[2];  
                                self.cityFlag = addressList[1];  

                            }  

                            self.getDeviceChild();  
                        },  
                        function(e) {  
                            console.log("失败回调", e);  
                        }  
                    );  

                },  
                fail: function(err) {  

                    uni.showToast({  
                        title: '获取定位失败',  
                        icon: 'error'  
                    });  
                }  
            });  

        },
2024-01-24 16:39 负责人:无 分享
已邀请:

要回复问题请先登录注册