I have a map inside my web application, which shows markers from my database. I use the google maps clustering option.
As seen in the following code, I use lat and lng (previously saved in my database) to generate bookmarks.
Looking in the google maps api documentation I have not known how to put more information to each marker
The idea is that when clicking on the marker, a modal opens with the info of that record in mysql, there is no problem with that. The thing is how do I add, for example, an id or class or tag to each marker?
Basically I want to implement this https://developers.google.com/maps/documentation/javascript/mysql-to-maps
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: {lat: 41.6041581, lng: -3.980962}
});
var labels = '';
var markers = locations.map(function(location, i) {
return new google.maps.Marker({
position: location,
label: labels[i % labels.length],
});
});
var markerCluster = new MarkerClusterer(map, markers,
{imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});
}
var locations = [
<?php
foreach ($rows as $row) {
?>
<?php if ($row['parametro'] != "5"): ?>
<?php echo "{lat: " . $row['lat'] . ", lng: " . $row['lng'] . "},"; ?>
<?php endif; ?>
<?php } ?>
]
</script>
This is how locations are generated.
var locations = [
{lat: 43.298215, lng: -1.961528},
{lat: 42.25115, lng: -2.841528},
{lat: 44.818215, lng: -1.05528},
]
How about I think you have not had any answer about this, but look at the ideal to add "markers" is that you build everything inside an array and use the method:
I'll show you how you can do it with a basic example, since clusters are groupings of "markers" and from what I see in your code you don't need that exactly.
In the code I make comments on how you can add the information
IMPORTANT: Put your api key
I am attaching a screenshot of the result.