我试图使用AGM (https://angular-maps.com/)在一个角4应用程序作为概念的证明,基本上从api得到一个json和动态显示在AGM地图中的位置。
不幸的是,api中的JSON似乎没有更新地图。
你知道为什么吗?
提前谢谢你。
export class HomeComponent implements OnInit {
public PageTitle: string = 'Location';
public latitude: number = 50.984795;
public longtitude: number = 8.9483832;
public zoom: number = 7;
public CompanyMarkers: marker[] ;
public localState = { value: '' };
constructor(
public appState: AppState,
public title: Title,
private http: HttpClient,
) {
}
getLocations() {
return this.http.get<marker[]>('api')
.map(res => res);
}
public ngOnInit() {
console.log('hello `Home` component');
this.getLocations().subscribe(data => {
this.CompanyMarkers = data;
console.log('init');
console.log(this.CompanyMarkers);
});
}
}
interface marker {
CompanyAccountId?:string;
companyName?:string;
latitude?: number;
longtitude?: number;
}
<agm-map
[latitude]="latitude"
[longitude]="longtitude"
[zoom]="zoom"
[disableDefaultUI]="false"
[zoomControl]="false">
<agm-marker
*ngFor="let m of CompanyMarkers;let i = index;"
[iconUrl]="'/assets/icon/icon-company.png'"
[latitude]="m.latitude"
[longitude]="m.longtitude">
<agm-info-window>
<strong>{{m.companyName}} </strong>
</agm-info-window>
</agm-marker>
</agm-map>发布于 2018-04-17 13:22:08
尝尝这个
<agm-marker
*ngFor="let m of CompanyMarkers;let i = index;"
[iconUrl]="'/assets/icon/icon-company.png'"
[position]="[m.latitude, m.longitude]">
<agm-info-window>
<strong>{{m.companyName}} </strong>
</agm-info-window>
</agm-marker> 还要检查你的经度拼写。
https://stackoverflow.com/questions/49877697
复制相似问题