I have a table html
that is created with a php
calling the database
Example:
<table>
<tr>
<th>id</th>
<th>Name</th>
</tr>
<?php
$query = "select id, name from pizza";
$result = $conn->query($query)
while ($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row['id'] . "</td>";
echo "<td>" . $row['Name'] . "</td>";
echo " <td><button id='button' onclick='SomeFunction()'> View stores </button></td></tr>";
}
?>
</table>
<!-- here is the map -->
<div id="map" class="mapcss">
<script type="text/javascript" src="func.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?
key=xxxxxxxxxxxxx&callback=myMap"></script>
</div>
and I have the function to create the map in a .js
function myMap() {
var center = new google.maps.LatLng(-33.4545832, -70.6541925);
map = new google.maps.Map(document.getElementById('map'), {
center: center,
zoom: 12
});
}
Also a function to add the markers, my problem is how to fill this array to place the markers on the map
function SomeFunction() {
var locations = [
*Data from db here*
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(-33.92, 151.25),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
}