gpt4 book ai didi

php - GoogleMap 和 WordPress : problems in creating markers dynamically

转载 作者:行者123 更新时间:2023-11-28 10:11:01 25 4
gpt4 key购买 nike

我想在 Wordpress 中的 GoogleMap 上动态创建标记。标记是根据帖子标签(都是位置)计算得出的。我在计算坐标和创建 php 数组方面没有问题。当我必须在 map 上绘制存储在数组中的动态生成的数据时,问题就出现了,因为没有显示指针

我在 WP header.php 中指定了以下说明:

  <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;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 帖子和标签动态获取数据时, header 中包含的 JavaScript 未正确完成。

任何建议都会有帮助:-(

干杯

码头

最佳答案

 var markers = [
{
'latitude': 62.3908358,
'longitude': 17.3069157,
'title': 'it happens in Sundsvall',
'news': 'che noia5'
},
];

您缺少一个结束撇号。我不确定这是否是问题所在,但您可以检查一下并确保不是问题。

除此之外,我不太确定,您也可以查看此链接:http://code.google.com/apis/maps/documentation/javascript/

关于php - GoogleMap 和 WordPress : problems in creating markers dynamically,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7430403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com