- 发布:2020-07-08 16:32
- 更新:2020-07-08 22:29
- 阅读:1207
产品分类: uniapp/App
PC开发环境操作系统: Mac
PC开发环境操作系统版本号: 10.14.6 (18G2022)
HBuilderX类型: 正式
HBuilderX版本号: 2.7.14
手机系统: 全部
手机厂商: 苹果
页面类型: vue
打包方式: 云端
项目创建方式: HBuilderX
测试过的手机:
示例代码:
export default {
data() {
return {
latitude: 39.909,
longitude: 116.39742,
markers: []
};
},
mounted() {
// 地图控件上下文
this.mapContext = uni.createMapContext("nearbyMap");
// 获取定位信息, 更新Markers
this.getLocationAddress();
},
methods: {
// 获取定位信息
getLocationAddress() {
uni.getLocation({
type: 'gcj02',
success: res => {
// // 更新经度
this.latitude = res.latitude
// 更新纬度
this.longitude = res.longitude
}
})
}
}
}
具体例子在附件demo中
export default {
data() {
return {
latitude: 39.909,
longitude: 116.39742,
markers: []
};
},
mounted() {
// 地图控件上下文
this.mapContext = uni.createMapContext("nearbyMap");
// 获取定位信息, 更新Markers
this.getLocationAddress();
},
methods: {
// 获取定位信息
getLocationAddress() {
uni.getLocation({
type: 'gcj02',
success: res => {
// // 更新经度
this.latitude = res.latitude
// 更新纬度
this.longitude = res.longitude
}
})
}
}
}
具体例子在附件demo中
操作步骤:
执行getLocationAddress之后地图map组件,一片灰白
执行getLocationAddress之后地图map组件,一片灰白
预期结果:
正常显示当前中心经纬度
正常显示当前中心经纬度
实际结果:
map组件一片灰白
map组件一片灰白
bug描述:
// 获取定位信息
getLocationAddress() {
uni.getLocation({
type: 'gcj02',
success: res => {
// // 更新经度
this.latitude = res.latitude
// 更新纬度
this.longitude = res.longitude
}
})
}
获取当前定位之后,修改经纬度,地图显示空白