Hello everyone !
I have a little project which i want to show the map with many markers and every marker can be clicked.
I just complete add markers by the useful tutorial on Google Map Cordova site. But i don’t know how to add the click event to each marker.
This is my script to add markers
addMarkers(data, function (markers) {
markers[markers.length - 1].showInfoWindow();
});
function addMarkers(data, callback) {
var markers = [];
function onMarkerAdded(marker) {
markers.push(marker);
if (markers.length === data.length) {
callback(markers);
}
marker.addEventListener(GoogleMapsEvent.INFO_CLICK, () => {
alert('fukc');
})
}
data.forEach((element) => {
map.addMarker({
'position': new GoogleMapsLatLng(element.location.lat, element.location.lng),
'title': element.title,
'snippet' : 'Đến điểm bán này',
}).then(onMarkerAdded);
});
}
Anyone can help me