According to the Google documentation, when you create a marker on a gmap the marker is also 'copied' onto the StreetView version of the map.
However, onClick event binding are not copied (or at least don't appear to be), so I can't open the InfoWindow on the marker when in StreetView.
Ideally I'd actually be able to define different content for the StreetView version of the InfoWindow, but right now I can't even get the same InfoWindow to open.
I'm using code from the Google examples to create the InfoWindow binding on the main map markers as follows (wrapped in a function):
google.maps.event.clearListeners(marker,'click');
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
// infoWindow.open(map.getStreetView(), marker);
});
That commented line was my attempt to add the opener for the StreetView version of the marker, but it doesn't do anything.
Note: map
is the map object, marker
is the marker object and html
contains the HTML string to be put into the InfoWindow. All of this works for the main map marker so it's mot a problem of null variables being passed or anything. The problem is only with getting the StreetView marker to pop it's InfoWindow when clicked.
Note that this is not a duplicate of Google Maps StreetView InfowIndows opening on map as this issue was due to a coding issue on my side and was solved using the steps in the accepted answer. The linked question refers to a change Google made to their API which broke some of this functionality or at least caused it to behave in an undesirable way.
My first error was that I was trying to display the same InfoWindow on both the map copy and the StreetView copy of the marker.
This is not allowed, and so creating a second instance of the InfoWindow fixed that problem.
In order to create two separate InfoWindows and attach them to the two copies of the same marker I had to modify my code somewhat.
The code above was from a function called
bindInfoWindow()
based on the code in the Google documentation. I modified this to include a parameter to specify either themap
or thestreetView
object.The next problem was that the
clearListeners
method was being called every timebindInfoWindow()
was being called, effectively removing theonClick
binding for the map copy of the marker.I therefore moved the
clearListeners
call to outside of the function and call it before calling binInfoWindow().The final function looks like below:
This is then called with the sequence:
What is nice about this is that if you open an InfoWindow on the map, then open StreetView the same InfoWindow is already open on the Street View!