I am trying to integrate google map in ionic project and got succeeded in displaying the google map on ionic page. But i want to display multiple markers on the this google map.
On one project i needed to do the same so i made this function. So you only need to put a for/foreach with the list you want to print and thats all.
Hope this help you.
private createMarker(position, label, element, icon) {
if (this.map != undefined) {
let marker = new google.maps.Marker({
position: position,
map: this.map,
icon: {
url: icon, // url
scaledSize: new google.maps.Size(40, 40), // scaled size
}
});
google.maps.event.addListener(marker, 'click', function () {
var infowindow = new google.maps.InfoWindow({
content: "content"
});
infowindow.open(this.map, marker);
});
} else {
console.log("map is undefined");
}
}
with loop you should be able to create the markers correctly with the function above:
this.markers.forEach(element => {
this.infomarkers.forEach(info => {
if (element.id == info.id) {
this.createMarker(element.position, element.label, info, element.icon);
}
});
});