【发布时间】:2017-11-25 06:09:15
【问题描述】:
这是我想要完成的,我正在调用一个函数 getGeoLocationOfUser(),我应该返回用户的地理位置,并且函数应该仅在地理位置可用或出现错误时返回。
但上述函数抛出错误声明类型既不是“void”也不是“any”的函数必须返回一个值。
public userGeolocation={latitude:null,longitude:null}
getGeoLocationOfUser():{latitude:any,longitude:any}{
this.geolocation.getCurrentPosition().then((resp) => {
this.userGeolocation.latitude=resp.coords.latitude;
this.userGeolocation.longitude=resp.coords.longitude;
console.log(this.userGeolocation);
localStorage.setItem('userGeoLocation',JSON.stringify(this.userGeolocation));
return this.userGeolocation;
//saving geolocation of user to localStorage
}).catch((error) => {
console.log('Error getting location', error);
return this.userGeolocation;
});
}
我可能在这里遗漏了一个非常基本的概念。任何帮助将不胜感激。
【问题讨论】:
-
很公平。@Rob 我最终放了很多 cmets,因为有很多问题的答案..人们急于成为 FGITW
标签: angular typescript ionic2