uni.getLocation({
type: 'gcj02',
geocode: true,
success: (res) => {
console.log(res,'当前定位')
this.city=res.address?res.address.city:''
// console.log('getCityCode(this.city)',getCityCode(this.city))
uni.request({
url:'http://www.weather.com.cn/data/sk/'+getCityCode(this.city)+'.html',
method: 'GET',
success: (res2) => {
console.log(res2,'天气')
this.wendu = res2.data.weatherinfo.temp + '°'
},
fail: (e) => {
console.log(e,'e')
this.$refs.uToast.show({
title: '天气加载失败',
type: 'warning'
})
}
})
}
})
- 发布:2022-10-17 10:22
- 更新:2023-09-26 14:09
- 阅读:259
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: windows7
HBuilderX类型: 正式
HBuilderX版本号: 3.5.3
手机系统: iOS
手机系统版本号: iOS 15
手机厂商: 苹果
手机机型: iphone 13pro Max
页面类型: vue
vue版本: vue2
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
操作步骤:
uni.getLocation({
type: 'gcj02',
geocode: true,
success: (res) => {
console.log(res,'当前定位')
this.city=res.address?res.address.city:''
// console.log('getCityCode(this.city)',getCityCode(this.city))
uni.request({
url:'http://www.weather.com.cn/data/sk/'+getCityCode(this.city)+'.html',
method: 'GET',
success: (res2) => {
console.log(res2,'天气')
this.wendu = res2.data.weatherinfo.temp + '°'
},
fail: (e) => {
console.log(e,'e')
this.$refs.uToast.show({
title: '天气加载失败',
type: 'warning'
})
}
})
}
})
uni.getLocation({
type: 'gcj02',
geocode: true,
success: (res) => {
console.log(res,'当前定位')
this.city=res.address?res.address.city:''
// console.log('getCityCode(this.city)',getCityCode(this.city))
uni.request({
url:'http://www.weather.com.cn/data/sk/'+getCityCode(this.city)+'.html',
method: 'GET',
success: (res2) => {
console.log(res2,'天气')
this.wendu = res2.data.weatherinfo.temp + '°'
},
fail: (e) => {
console.log(e,'e')
this.$refs.uToast.show({
title: '天气加载失败',
type: 'warning'
})
}
})
}
})
预期结果:
定位返回address数据
定位返回address数据
实际结果:
定位不返回address数据
定位不返回address数据
bug描述:
在ios系统上运行app ,调用 uni.getloaction后,返回数据没有address,在安卓端正常,
第三方定位key已经配置