Wordpress で GoogleMap に動的にマーカーを作成したいと思います。マーカーは投稿タグ (すべての場所) から計算されます。座標の計算とphp配列の作成に問題はありません。問題は、ポインターが表示されないため、配列に格納された動的に生成されたデータをマップにプロットする必要がある場合に発生します。
WP header.php で次の指示を指定しました。
<script src="http://maps.google.com/maps?file=api&v=2&key=mykey" type="text/javascript"></script>
<script src="<?php bloginfo('template_directory'); ?>/mapLocations_cache.php" type="text/javascript"></script>
<script src="<?php bloginfo('template_directory'); ?>/map_functions.js" type="text/javascript"></script>
動的に作成された配列 (mapLocations_cache.php に保存) の形式は次のとおりです。
var markers = [
{
'latitude': 62.3908358,
'longitude': 17.3069157,
'title': 'it happens in Sundsvall',
'news': 'che noia5'
},
];
map_functions.js には次のコードが含まれています。
var centerLatitude = 62.3908358;
var centerLongitude = 17.3069157;
var startZoom = 4;
var map;
function addMarker(latitude, longitude, description) {
var marker = new GMarker(new GLatLng(latitude, longitude));
GEvent.addListener(marker, 'click',
function() {
marker.openInfoWindowHtml(description);
}
);
map.addOverlay(marker);
}
function init() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
for(id in markers) {
addMarker(markers[id].latitude, markers[id].longitude, markers[id].title);
}
}
}
window.onload = init;
window.onunload = GUnload;
動的に生成されていないファイル/配列を使用すると、このコードはうまく機能するため、WordPress の投稿とタグから動的にデータを収集しようとすると、ヘッダーに含まれる JavaScript が適切に完了していないのではないかと疑っています。
どんな提案も役立ちます:-(
乾杯
マリーナ