I am working on an Ionic app . My app is get data json api earthquake form USGS then set coordinates on google map . l’m looping over an array to create markers and infowindows , but the infowindow is always attached to the first marker information even if click on others icon l get same information !
export class HomePage implements OnInit {
protected points: { lng: number, lat: number }[] = [];
items: any
pet: string = "Today";
map: GoogleMap;
mags: number;
constructor(
private http: HTTP) {
}
async ngOnInit() {
this.getData()
}
async getData() {
this.http.get(`https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.geojson`, {}, {}).then(data => {
this.items = JSON.parse(data.data)
let earth = JSON.parse(data.data)
console.log(this.items)
let htmlInfoWindow = new HtmlInfoWindow();
for (let datas of earth['features']) {
this.points.push({ lng: datas.geometry.coordinates[0], lat: datas.geometry.coordinates[1] });
let mag = datas.properties.place
let title = datas.properties.title
/// Marker icon
let dest = this.points.map((coords) => {
return this.map.addMarker({
position: coords,
icon: this.mags_icons
}).then((marker: Marker) => {
marker.on(GoogleMapsEvent.MARKER_CLICK).subscribe(() => {
htmlInfoWindow.open(marker);
});
});
});
let frame: HTMLElement = document.createElement('div');
frame.innerHTML =
'<h3>' + mag + '</h3>',
'<p>' + title + ' </p>';
frame.addEventListener("click", (evt) => {
});
htmlInfoWindow.setContent(frame, {
width: "170px"
});
this.map = GoogleMaps.create('map_canvas');
}
})
}
}
any idea please ?