【发布时间】:2021-05-10 04:50:34
【问题描述】:
我已将地理定位调用置于我想在应用程序的不同区域使用的服务中。但是,未定义正在被返回。如何正确返回值以便检索?
服务代码
getUserPosition() {
this.geolocation.getCurrentPosition().then((position) => {
this.latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
this.currentLat = position.coords.latitude;
this.currentLng = position.coords.longitude;
return this.latLng;
}, (err) => {
console.log('There was an error');
});
}
从服务调用这个函数
async ngOnInit() {
// Since ngOnInit() is executed before `deviceready` event,
// you have to wait the event.
await this.platform.ready();
await this.loadMap();
this.val = await this.location.getUserPosition();
console.log("I should be here val "+ this.val);
}
【问题讨论】:
-
你能发布完整的 SSCCE 吗?
标签: angular google-maps service ionic3 google-geolocation