google maps api v3 - open infowindow from an external click

google-maps, google-maps-api-3, javascript, jquery

Solution

You might use `trigger` event.

$('#marker25837500').click(function () {
    google.maps.event.trigger(marker25837500, 'click')
})

Check this- https://developers.google.com/maps/documentation/javascript/reference#event

Edit: Also noticed that you are calling `onMarkerClick()` when `marker25837500` is clicked, but you named the other function `OpenInfoWindow()` so you might need to change that too.

Problem

So i have a V3 map which is initialised like this: ``` function init() { var mapCenter = new google.maps.LatLng(51.5081289,-0.128005); var map = new google.maps.Map(document.getElementById('map'), { 'zoom': 6, 'center': mapCenter, 'mapTypeId': google.maps.MapTypeId.ROADMAP, panControl: false, mapTypeControl: false, zoomControl: true, zoomControlOptions: { style: google.maps.ZoomControlStyle.SMALL, position: google.maps.ControlPosition.LEFT_TOP }, }); ``` and a load of markers that look like this: ``` var marker25837500 = new google.maps.Marker({ map: map, pop_title: 'blah blah', pop_wind: 'more blah', zIndex: 999, icon: 'images/map_icons/s6.png' }); google.maps.event.addListener(marker25837500, 'click', onMarkerClick); ``` and lastly i have a function to open the infowindow on he click of each maker: ``` var infoWindow = new google.maps.InfoWindow; var onMarkerClick = OpenInfoWindow; function OpenInfoWindow() { var marker = this; infoWindow.setContent('<h3>' + marker.pop_title + '</h3>' + marker.pop_body); infoWindow.open(map, marker); }; google.maps.event.addListener(map, 'click', function() { infoWindow.close(); }); ``` My question is, what do i need to do to make a particular marker (say marker25837500) show its infowindow when a inside the page is clicked - perhaps something like: ``` <div id="marker25837500">click to see infoWindow!</div> ``` I'm sure it's easy but i just can see my way though it! Thanks

Original source