在我不熟悉的应用程序中遇到了一个问题,我不是通常的开发环境,因此我不知道这段代码是怎么回事。
代码是将图钉放置在地图上,其中有一个地图组件定义为
export class FuseGoogleMapsDocsComponent {
@Input() coordinates = [{ 'lat': -34.397, 'lng': 150.644 }];
@Input() ceterLat = -34.397;
@Input() ceterLng = 150.644;
constructor() {
}
有一个引用组件的HTML标记
<fuse-google-maps-docs [ceterLat]="centerLat" [ceterLng]="centerLng" [coordinates]="coordinates"></fuse-google-maps-docs>
但是当填充坐标数组时,数组始终是不确定的
该数组声明为
coordinates = [];
填充数组的函数是:数组返回39行,循环成功完成,但是在push语句之后,坐标数组未定义。
public GetIpListMap() {
const DataUrl = 'api/IPTracking/GetUserIPAddress?userID=' + this.userID;
this._http.get(DataUrl).subscribe(response => {
let maps = response.data;
let allLat = 0;
let allLng = 0;
let i = 0;
maps.forEach(item => {
allLat += item.latitude;
allLng += item.longitude;
const coordinate = { lat: item.latitude, lng: item.longitude};
i += 1;
this.coordinates.push(coordinate);
});
this.centerLat = allLat / i;
this.centerLng = allLng / i;
});
}
我确信这确实很简单,但我似乎无法解决。
感谢您的帮助