Note that there are some explanatory texts on larger screens.

plurals
  1. POI'm trying to position google maps with a table row click
    primarykey
    data
    text
    <p>On my webpage when the page loads it loads a table generated by content from my database, and all markers are instantly loaded on the map, but I'd like to be able to click on the table row to center and zoom on the marker that it represents, I'm trying to figure it out but I'm new to JQuery/Javascript just kind of learning as I go.</p> <p>Here is my JQuery function I'm working on..</p> <pre><code>$("table#listOfStops").find('tr').each(function() { $(this).on('click', function() { alert(arrMarkers.length); var num = $(this).data("num"); for (var i = 0; i &lt; arrMarkers.length; i++) { if ( arrMarkers.id == 'marker'+num) { map.setCenter(arrMarkers[i].position); map } } }); }); </code></pre> <p>Here is my table: </p> <pre><code> &lt;table id="listOfStops" class="table table-striped"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Stop #&lt;/th&gt; &lt;th&gt;Street Name&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;?php $i = 0; while($stmt -&gt; fetch()) { echo '&lt;tr id="' . $i . '"&gt;'; echo '&lt;td&gt;' . $gStopNumber . '&lt;/td&gt;'; echo '&lt;td&gt;' . $gStreetName . '&lt;/td&gt;'; echo '&lt;/tr&gt;'; $i++;} $stmt -&gt; close(); $mysqli -&gt; close(); ?&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>On page load it loads this initialize function:</p> <pre><code>function initialize() { geocode = new google.maps.Geocoder(); var mapOptions = { zoom: 10, center: new google.maps.LatLng(56.7626362, -111.379652), mapTypeId: google.maps.MapTypeId.ROADMAP, disableDefaultUI: false, zoomControl: true, zoomControlOptions: { style: google.maps.ZoomControlStyle.LARGE } }; map = new google.maps.Map(document.getElementById('gmaps'), mapOptions); google.maps.event.addListener(map, 'click', function(event) { var latitude = event.latLng.lat(); var longitude = event.latLng.lng(); deleteOverlays(); addMarker(event.latLng); updateTextFields(latitude, longitude); }); &lt;?php while($stmt -&gt; fetch()) { ?&gt; var long = "&lt;?php echo $gLongitude ?&gt;"; var lati = "&lt;?php echo $gLatitude; ?&gt;"; var title = "&lt;?php echo $gTitle; ?&gt;" setMarker(lati, long, title); &lt;?php } $stmt -&gt; close(); $mysqli -&gt; close();?&gt; } </code></pre> <p>and then sets each marker to the map and pushes them to an array using the setMarker function: </p> <pre><code>function setMarker(lat,lon, markerTitle) { var latLonMarker = new google.maps.LatLng(lat,lon); marker = new google.maps.Marker({ position: latLonMarker, map: map, icon: 'icon.png', title: markerTitle }); google.maps.event.addListener(marker, 'dragend', function() { $('#inputLatitude').val(this.getPosition().lat()); $('#inputLongitude').val(this.getPosition().lng()); }); arrMarkers.push(marker); } </code></pre> <p>I'm just having an impossibly hard time matching the table row to the proper marker spot in the marker array to set the position something like <code>map.setPosition(arrMarkers[i]);</code></p> <p>Thanks in advance.</p>
    singulars
    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.
 

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