I'm using cakephp and this project is about estates. I'm trying to put estates with picture on google map. My current code is like
<script>
var map;
var infoWindow;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 36.591258, lng: 136.624976},
zoom: 9,
styles:[
{
"featureType": "landscape",
"elementType": "all",
"stylers": [
{
"color": "#e4e4e4"
}
]
},
{
"featureType": "poi",
"elementType": "all",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "road",
"elementType": "all",
"stylers": [
{
"saturation": -100
},
{
"lightness": 45
}
]
},
{
"featureType": "road.highway",
"elementType": "all",
"stylers": [
{
"visibility": "simplified"
}
]
},
{
"featureType": "road.highway",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#fc9700"
}
]
},
{
"featureType": "road.arterial",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#c5c5c5"
}
]
},
{
"featureType": "road.arterial",
"elementType": "labels.icon",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "road.local",
"elementType": "all",
"stylers": [
{
"visibility": "on"
}
]
},
{
"featureType": "transit",
"elementType": "all",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "water",
"elementType": "all",
"stylers": [
{
"color": "#999797"
},
{
"visibility": "on"
}
]
}
],
});
<?php foreach ($rooms as $k => $room): ?>
var marker = new google.maps.Marker({
position: {lat: <?= h($room['estate_latitude']) ?>, lng: <?= h($room['estate_longitude']) ?>},
map: map,
icon: new google.maps.MarkerImage(
'<?= $this->Url->build('/') ?>img/ico_pin.svg',
new google.maps.Size(30, 30),
new google.maps.Point(0, 0),
new google.maps.Point(21, 21)
),
});
infoWindow<?= $k ?> = new google.maps.InfoWindow({
content: '<div class="area_wall_balloon"></div><div class="img_arrow"></div>'
});
marker.addListener('click', function() {
infoWindow<?= $k ?>.open(map, marker);
});
<?php endforeach; ?>
var mapStyle = [ {
"stylers": [ {
"saturation": -100,
} ],
} ];
}
</script>
enter image description here The problem that I'm trying to solve is that when I click 2, 1's window shows up :( I added the screenshot. I would appreciate it if you could give me advices.