It is assumed that we already have an initialized map and markers stored in a certain array.

Task: for a certain house-event, you need to display an information window at the corresponding label.

The code below works, but the information window opens in the upper left corner of the map without being tied to a specific marker. If I try to pass the corresponding marker to the second parameter, i.e. instead of infowindow.open (map); I write infowindow.open (map, marker); then I get the Uncaught TypeError error message in the console : b.get is not a function.

Why and how to solve this issue?

$.each( markers, function( key, marker ) { if (marker.id == activeStore) { console.log(marker); console.log(map); //Всплывашка var contentString = '<b>' + marker.title +'</b>' + '<br>' + marker.description + //'<br>' + 'Адрес: ' + this.address + '<br>' + 'Телефон: ' + marker.phone + '<br>' + 'Режим работы: ' + marker.schedule; var infowindow = new google.maps.InfoWindow({ content: contentString }); arrInfoWindows[arrInfoWindows.length] = infowindow; infowindow.open(map); // Центрируем и масштабируем карту //map.setCenter(markersBounds.getCenter(), map.fitBounds(markersBounds)); } }); 

  • What event, for example? Events on the marker? - Sv__t
  • No, not on the marker. Onclick on an arbitrary DOM page element. - Zhdun
  • And how do you add markers? You can, for example, add a listener to some AddMarker function, which then displays InfoWindow - Sv__t
  • And what will the listener look like, who displays InfoWindow by clicking on the a.show page element (it has no relation to maps at all, just a markup element)? - Zhdun

1 answer 1

Most likely you have a variable marker - this is not a Google Maps object, in order to display an information window next to the marker, you must pass the map and marker object to the open method.