我想知道当用户按下某个按钮并将其按到数据库中具有用户id的某个表时的位置。
我如何在IONIC 5中做到这一点?
发布于 2019-12-23 07:04:12
欢迎来到Stackoverflow!
你试过'@ionic-native/geolocation'和Google Maps API吗?你可以这样做:
1 -获取当前位置。我们有两个变量:纬度和经度
getCurrentLocation() {
let options = {timeout : 10000 , enableHighAccuracy:true};
let locationObs = new Observable(observable => {
this.geolocation.getCurrentPosition(options)
.then(resp => {
this.latitude = resp.coords.latitude
this.longitude = resp.coords.longitude
let location = new google.maps.LatLng(this.latitude, this.longitude);
observable.next(location);
}).catch( error => {
loading.dismiss();
return false;
})
})
return locationObs;
}
2 -单击按钮时调用函数。要防止内存泄漏,请在获得以下位置后使用取消订阅:
buttonClicked(){
let sub = this.getCurrentLocation().subscribe(location => {
console.log(this.latitude, this.longitude)
sub.unsubscribe()
})
}
如果你有更多的问题,请告诉我。
https://stackoverflow.com/questions/59444673
复制相似问题