我正在使用Capacitor来构建我的Ionic应用程序。 在应用程序中,我想要通过GPS显示当前位置的地图。
以下代码可以正常工作,并像我希望的那样在地图上给出正确的标记,但是……它远非准确。
async getLocation() {
var self = this;
let location = await Geolocation.getCurrentPosition({
enableHighAccuracy: true,
timeout: 1000
});
self.marker.setLngLat([location.coords.longitude, location.coords.latitude])
const wait = Geolocation.watchPosition({enableHighAccuracy: true, timeout: 1000}, (position, err) => {
self.marker.setLngLat([position.coords.longitude, position.coords.latitude])
});
}
标记器正在疯狂地旋转,无论我在哪个位置测试它都会出现。它不是以厘米为单位移动,而是以米为单位围绕着我的位置移动... 我错过了什么导致我得到不够精确的GPS坐标?我原以为设置 "enableHighAccuracy: true" 就足够了,但事实并非如此。