uni.getSetting({
success(res) {?
if (!res.authSetting['scope.userLocation']) {
// 未授權
uni.authorize({
scope: 'scope.userLocation',
success() { //1.1 允許授權
? uni.getLocation({
type: 'gcj02',
geocode:true,//設置該參數(shù)為true可直接獲取經緯度及城市信息
success: function (res) {
uni.setStorageSync("locationLat",res.latitude)
uni.setStorageSync("locationLng",res.longitude)
uni.request({
? url: 'http://api.map.baidu.com/reverse_geocoding/v3/?ak=Tolbv6WmfNq8bMNaT729T9sxuGRoysYH&location=' + res.latitude + ',' + res.longitude + '&output=json',
? data: {},
? header: {
? ? 'Content-Type': 'application/json'
? },
? success: function (res) {
? if(res.data.status == 0){
? uni.setStorageSync("city_name",res.data.result.addressComponent.city)
? that.nvConfig.address.county = res.data.result.addressComponent.city
? uni.setStorageSync("index_province_name",res.data.result.addressComponent.province)
? uni.setStorageSync("index_city_name",res.data.result.addressComponent.city)
? that.getdata()
? that.loadData(1);
? }
? },
})
},
? });
},
})
}
that.getdata()
}
});