setInterval(() => {
uni.getLocation({
type: "gcj02",
isHighAccuracy: true,
success: (res) => {
let longitude = res.longitude;
let latitude = res.latitude;
//polyline
this.polyline[0].points.push({ longitude, latitude });
//center
this.longitude = longitude;
this.latitude = latitude;
//marker
this.covers[0].longitude = longitude;
this.covers[0].latitude = latitude;
this.polyline = [...this.polyline];
this.covers = [...this.covers];
},
fail: (res) => {}
});
}, 10000);
- 发布:2023-04-21 09:10
- 更新:2024-06-25 23:37
- 阅读:743
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: windows10 22H2
HBuilderX类型: 正式
HBuilderX版本号: 3.7.9
手机系统: Android
手机系统版本号: Android 11
手机厂商: realme
手机机型: realme X2
页面类型: vue
vue版本: vue2
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
操作步骤:
<map id="map" style="width: 100%; height: 300px;margin: 10rpx 0;" :latitude="latitude" :longitude="longitude" :markers="covers" :polyline='polyline' />
setInterval(() => {
uni.getLocation({
type: "gcj02",
isHighAccuracy: true,
success: (res) => {
let longitude = res.longitude;
let latitude = res.latitude;
//polyline
this.polyline[0].points.push({ longitude, latitude });
//center
this.longitude = longitude;
this.latitude = latitude;
//marker
this.covers[0].longitude = longitude;
this.covers[0].latitude = latitude;
this.polyline = [...this.polyline];
this.covers = [...this.covers];
},
fail: (res) => {}
});
}, 10000);
<map id="map" style="width: 100%; height: 300px;margin: 10rpx 0;" :latitude="latitude" :longitude="longitude" :markers="covers" :polyline='polyline' />
setInterval(() => {
uni.getLocation({
type: "gcj02",
isHighAccuracy: true,
success: (res) => {
let longitude = res.longitude;
let latitude = res.latitude;
//polyline
this.polyline[0].points.push({ longitude, latitude });
//center
this.longitude = longitude;
this.latitude = latitude;
//marker
this.covers[0].longitude = longitude;
this.covers[0].latitude = latitude;
this.polyline = [...this.polyline];
this.covers = [...this.covers];
},
fail: (res) => {}
});
}, 10000);
预期结果:
一条比较正常的轨迹
一条比较正常的轨迹
实际结果:
轨迹飘忽不定,很多分叉,来回移动
轨迹飘忽不定,很多分叉,来回移动
bug描述:
发布的是app,每隔10秒,使用uni.getLocation获取手机位置,然后在map地图上绘制轨迹,结果绘制出来的轨迹经常出现偏移,明明是一条直线轨迹,结果取到的点位来回跳动,出现分叉。已经申请了高德安卓平台的key和证书。坐标系采用的是gcj02。PS:有没有别的解决方案呢?