gpt4 book ai didi

javascript - 观看位置 Ionic 3

转载 作者:行者123 更新时间:2023-12-03 01:41:56 24 4
gpt4 key购买 nike

大家好,我需要帮助如何使用 Ionic 3 查看 google map 中的位置,我希望在 firebase 中实时上传位置在我的 home.ts 中,我有以下代码:

    getMyPosition() {
this.geolocation.getCurrentPosition().then((result) => {
this.positionTruck = new google.maps.LatLng(result.coords.latitude, result.coords.longitude);
const mapOptions = {
zoom: 18,
center: this.positionTruck,
disableDefaultUI: true
}
this.map = new google.maps.Map(document.getElementById('map'), mapOptions);
this.truckMarker(this.positionTruck);

let watch = this.geolocation.watchPosition();
watch.subscribe((data) => {
let truck = { latitude: data.coords.latitude, longitude: data.coords.longitude };
this.truckService.updateGeolocation(this.truck.key, truck);
console.log(data.coords)
});

}).catch((error) => {
console.log('Erro ao tentar pegar sua localização ', error);
})
}

现在我有这个代码来更新 Truck.service:

    update(key: string, truck: any) {
return new Promise((resolve, reject) => {
this.db.list(this.PATH)
.update(key, (truck))
.then(() => resolve())
.catch((e) => reject())
})
}

这样当我在设备上测试时,主页会刷新页面,为什么?该表格的更新位置是否正确?请帮忙。

最佳答案

导入:从'@ionic-native/geolocation'导入{地理位置,地理位置};

并声明:

public lat: number = 0;
public lng: number = 0;

并添加您的代码

let options = {
frequency: 3000,
enableHighAccuracy: true
};

this.watch = this.geolocation.watchPosition(options).filter((p: any) => p.code === undefined).subscribe((position: Geoposition) => {

console.log(position.coords.latitude + ' ++++++++++ ' + position.coords.longitude);

// Run update inside of Angular's zone
this.zone.run(() => {
this.lat = position.coords.latitude;
this.lng = position.coords.longitude;
);

});

});

关于javascript - 观看位置 Ionic 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50799208/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com