Pablo Malynovytch Pablo Malynovytch - 1 month ago 5x
Javascript Question

How to get the id when is clicked and remove that? Google Maps V3

Here is my code...I try to put event listener but the console says:

markers.addListener is not a function

Here is my code.....

//The problem :(
markers.addListener('click', function() {
var marker = this;

<!--My API-->
<script async defer type="text/javascript" src=",places&callback=initMap"></script>


You can only add Google Maps click listeners to a Google Maps objects that support click events (like a google.maps.Marker. markers is not a google.maps.Marker, it is an Array. Arrays don't have the method .addListener.

One option would be to add the click listener to the marker when you create it:

// Adds a marker to the map and push to the array.
function addMarker(location) {
  var marker = new google.maps.Marker({
    position: location,
    map: map
  marker.addListener('click', function() {
    var marker = this;
  countmarkers ++;
  count ++;