2***@qq.com
- 发布:2022-08-31 11:40
- 更新:2023-08-23 15:49
- 阅读:792
测试过的手机:
操作步骤:
plus.geolocation.getCurrentPosition(WhenAddress, function(e) {});
// 获取当前地址
function WhenAddress(position) {
Lon = position.coords.longitude; //获取经度
Lat = position.coords.latitude; //获取纬度
var address = '';
console.log(JSON.stringify(position));
address += !position.address.province ? "" : position.address.province;
address += !position.address.city ? "" : "," + position.address.city;
address += !position.address.district ? "" : "," + position.address.district;
}
plus.geolocation.getCurrentPosition(WhenAddress, function(e) {});
// 获取当前地址
function WhenAddress(position) {
Lon = position.coords.longitude; //获取经度
Lat = position.coords.latitude; //获取纬度
var address = '';
console.log(JSON.stringify(position));
address += !position.address.province ? "" : position.address.province;
address += !position.address.city ? "" : "," + position.address.city;
address += !position.address.district ? "" : "," + position.address.district;
}
预期结果:
可以正常使用
可以正常使用
实际结果:
报错:TypeError: Cannot read property 'province' of undefined
报错:TypeError: Cannot read property 'province' of undefined
bug描述:
升级最新版本,HBuilder X 3.5.3 后,使用
plus.geolocation.getCurrentPosition 获取不到address。
版本降级后 HBuilderX.2.7.14 后 正常使用。
我怎么处理一下 在最新版本可以正常使用呢?
3 个回复
CODE_XU
这是我用 iPhone6 测试获取的地址
2***@qq.com (作者) - 介绍一下
我用最新的HBuilder X 3.5.3
手机 iphone xr :
打印的数据:{"coordsType":"wgs84","address":{"city":"济南市","country":"中国","district":"槐荫区","province":"山东省","street":"齐州路","streetNum":"106号"},"addresses":"齐州路106号","coords":{"latitude":36.68052455041013,"longitude":116.8938524060198,"accuracy":65,"altitude":29.16618728637695,"heading":null,"speed":null,"altitudeAccuracy":10},"timestamp":1661922049293.933}
华为 p40:
打印的数据:{"coordsType":"wgs84","coords":{"latitude":36.680837,"longitude":116.89551,"accuracy":22.492844,"altitude":0,"heading":null,"speed":0,"altitudeAccuracy":0},"timestamp":null}
y_j_x
我也遇到这个问题,怎么处理