各マーカーにバインドされたInfoWindowsでJSONを使用して、Googleマップに複数のマーカーを配置しようとしています。残念ながら、JSONの最後の値であるマーカーが1つだけ表示されます。他のマーカーは表示されず、コミックバルーンスタイルの矢印は情報ウィンドウの後ろに表示されません。これを解決するためにかなり長い間試みましたが、何も機能していないようです。
これはコードです:
var stories = {{story_Json|safe}};
var map;
function loadMarkers(stories){
for (i=0;i<stories.length;i++) {
var story = stories[i];
var point = new google.maps.LatLng(story.latitude, story.longitude);
var marker = new google.maps.Marker({position: point, map: map});
var infowindow = new google.maps.InfoWindow({
content: '<div >'+
'<div >'+
'</div>'+
'<h2 class="firstHeading">'+story.headline+'</h2>'+
'<div>'+
'<p>'+story.copy+'</p>'+
'</div>'+
'</div>'
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
}
}
function mainMap(position)
{
// Define the coordinates as a Google Maps LatLng Object
var coords = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
// Prepare the map options
var mapOptions =
{
zoom: 15,
center: coords,
mapTypeControl: false,
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// Create the map, and place it in the map_canvas div
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
// Place the initial marker
var marker = new google.maps.Marker({
position: coords,
map: map,
title: "Your current location!"
});
loadMarkers(stories);
}
これらの問題への洞察は大歓迎です。