angular - IONIC中的返回值形式函数
问题描述
我尝试学习 IONIC 5。我使用本地地理定位来返回纬度和经度。从这个函数中,我需要检索经纬度,然后通过表格发送到服务器。
geolocate()
{
this.geolocation.getCurrentPosition().then((resp) => {
let position = {
latitude: resp.coords.latitude,
longitude: resp.coords.longitude
}
return position;
}).catch((error) => {
console.log('Error getting location', error);
});
}
使用这个其他功能
login(form: NgForm) {
this.geolocate();
this.authService.login(form.value.email, form.value.password, this.latitude, this.longitude).subscribe(
data => {
this.alertService.presentToast("Logged In");
},
error => {
console.log(error);
},
() => {
this.dismissLogin();
this.navCtrl.navigateRoot('');
}
);
}
解决方案
async login(form: NgForm) {
let res = await this.geolocate();
this.latitude = res.latitude;
this.longitude = res.longitude;
this.authService.login(form.value.email, form.value.password, this.latitude, this.longitude).subscribe(
data => {
this.alertService.presentToast("Logged In");
},
error => {
console.log(error);
},
() => {
this.dismissLogin();
this.navCtrl.navigateRoot('');
}
);
}
推荐阅读
- c++ - 有什么方法可以用 C++ 打印我的上标多项式指数?
- visual-studio - 将文件复制到输出目录到另一个项目的输出目录
- python - Discord bot python-在文本文件中写入和日志记录
- php - 使用 Content-Type 调用 api 时出现问题:application/json (lumen/react fetch)
- excel - 以逗号分隔的多个数据到不同的列
- html - 垂直对齐(Flexbox)和中心对齐有问题
- html - 如何将使用 html/css 制作的模态添加到我的引导网站?
- reactjs - 如何使用mapbox在同一图层中绘制多个不同颜色的点?
- tensorflow - 训练对象检测模型时,张量板图像选项卡上没有显示边界框是否正常?
- javascript - 我将如何有效地打印每个“官方”表情符号字符?