Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding jQuery element clicks with Google Map Markers
    primarykey
    data
    text
    <p>I am using jQuery to bind my map sidebar as part of my map scripting. When I do this, I just have one tiny problem. When you click on the sidebar links, it always reverts to opening the last marker’s infoWindow.</p> <p>Which means I binding my links incorrectly or I am trigger the marker event incorrectly. If someone can help point me in the right direction ... much appreciated. </p> <p>Scripting I am using.</p> <pre><code>var listings=[new google.maps.LatLng(43,-79),new google.maps.LatLng(43,-79),new google.maps.LatLng(43,-79)]; var names=['name 1','name 2','name 3']; var descriptions=['description 1','description 2','description 3']; var image = new google.maps.MarkerImage('/flag.png',new google.maps.Size(24,24),new google.maps.Point(0,0),new google.maps.Point(0,0)); var map; var box; function initialize() { var moptions = { zoom: 6, center: new google.maps.LatLng(43,-79), mapTypeId: google.maps.MapTypeId.ROADMAP, visible: true } var div = document.createElement('div'); var boptions = { content: div, disableAutoPan: false, maxWidth: 0, pixelOffset: new google.maps.Size(-140, 0), zIndex: null, boxStyle: { background: "url('tipbox.gif') no-repeat", opacity: 0.75, width: "280px" }, closeBoxMargin: "10px 2px 2px 2px", closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif", infoBoxClearance: new google.maps.Size(1, 1), isHidden: false, pane: "floatPane", enableEventPropagation: false }; box = new InfoBox(boptions); for (var i = 0; i &lt; listings.length; i++) { var marker = new google.maps.Marker({ position: listings[i], map: map, draggable: false, icon: image, title: names[i] }); AttachMessage(marker, i); } } function AttachMessage(marker, number) { google.maps.event.addListener(marker, 'click', function() { box.close(); box.setContent(descriptions[number]); box.open(map, marker); }); //this is where I am having the issue ... $('#sidebar').find('#marker').unbind('click').bind('click', function (e) { google.maps.event.trigger(marker, 'click'); }); } </code></pre> <p>Sidebar Marker Links</p> <pre><code>&lt;div id="sidebar"&gt; &lt;ul&gt; &lt;li&gt;&lt;a id="marker" href="#"&gt;Marker One&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a id="marker" href="#"&gt;Marker Two&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a id="marker" href="#"&gt;Marker Three&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload