【发布时间】:2017-05-03 13:33:09
【问题描述】:
我是 Ionic 2 的新手,正在学习一些教程。
在这种情况下,我需要更改以下方法:
applyHaversine(locations){
let usersLocation = {
lat: 40.713744,
lng: -74.009056
};
locations.map((location) => {
let placeLocation = {
lat: location.latitude,
lng: location.longitude
};
location.distance = this.getDistanceBetweenPoints(
usersLocation,
placeLocation,
'miles'
).toFixed(2);
});
return locations;
}
可以看到变量 usersLocation 是硬编码的:
let usersLocation = {
lat: 40.713744,
lng: -74.009056
};
我想获得真实的用户位置。
我见过 Geolocation.getCurrentPosition() 方法,但我不知道在这种情况下如何实现它。
谢谢
已编辑
applyHaversine(locations){
Geolocation.getCurrentPosition().then((resp) => {
let latitud = resp.coords.latitude
let longitud = resp.coords.longitude
}).catch((error) => {
console.log('Error getting location', error);
});
console.log(this.latitud);
let usersLocation = {
lat: this.latitud,
lng: this.longitud
};
【问题讨论】: