0

I've been struggling with setting up a listener and opening content above a marker lately. When I click on the marker, nothing happens.

I tried approaching this through calling showInfo() from the pset specs, as mentioned in other posts like this and this. I have also tried switching to an info window, but that didn't seem to work well either.

Here's what I did:

var latLng = new google.maps.LatLng(place.latitude, place.longitude);

var marker = new google.maps.Marker({
  position: latLng,
  map: map,
  title: "place.place_name"+ "place.admin_name1"
});
arr.push(marker)

marker.setMap(map);

var content = "hello";

google.maps.event.addListener(marker, 'click', function(){
  map.setCenter(marker.getPosition());
  showInfo(marker, content);
});

Thanks for your time!

1 Answer 1

1

All things being equal, this arr.push(marker) is a problem. The distro code initializes an array called markers; unless you have initialized an array called arr, this line will give an error in the console "ReferenceError: arr is not defined" One marker is created, and the function bails before the listener is instantiated.

1
  • Thank you very much! I completely missed this after looking at the code for so long.
    – soonthoj
    Commented May 5, 2019 at 8:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .