我想将来自getLocation
的信息存储在位置数组中,并将值转换为float。但我不知道如何循环存储值
this.peopleservice.getLocation(ID)
.subscribe(data =>{this.latcoor = data[x].lat,
this.lngcoor=data[x].lng
this.lat= parseFloat(this.latcoor);
this.lng= parseFloat(this.lngcoor);
this.location= [
{latitude:this.lat, longitude:this.lng},
];
});}
答案 0 :(得分:1)
使用for
循环如下:
this.peopleservice.getLocation(ID)
.subscribe(data => {
this.location = [];
for (let item of data) {
this.location.push({latitude: parseFloat(item.lat), longitude: parseFloat(item.lng)});
}
});