Googleマップに複数のマーカーがあり、それらをクリックするとモーダルウィンドウを開く必要があります。問題は、すべてのマーカーに特定の ID があり、各モーダルでその ID が必要なことです。
モーダルhtmlは次のとおりです。
<div class="modal fade" id="imageModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
この関数を呼び出す JavaScript コードは次のとおりです。
function createMarker(pos, t, map) {
var marker = new google.maps.Marker({
position: pos,
map: map, // google.maps.Map
index: t
});
google.maps.event.addListener(marker, 'click', function() {
$('#imageModal').modal();
//alert("I am marker " + marker.index);
});
return marker;
}
したがって、imageModal では、動的な marker.index 情報にアクセスする必要があります。どうやってやるの?何か案は ?