0

我设法实现了 Google Maps Api,并通过函数从 Wordpress 数据库中加载了标记。但我不知道如何将自定义图标添加到标记别针。问题是 Wordpress 不允许直接访问模板文件。

我的图片加载到了主题/主题名/img/bgi

脚本如下所示:

var myLatlng = new google.maps.LatLng(data[i].latitude,data[i].longitude);
                    marker = new google.maps.Marker({
                            position: myLatlng,
                            //icon: data[i].image,
                            map: map,
                            title: data[i].title
                    });
4

1 回答 1

2

我将以下内容用于我的解决方案 - 主题目录中文件的绝对路径:

<?php bloginfo('template_directory'); ?>/img/marker.png
<?php bloginfo('template_directory'); ?>/img/marker-shadow.png

所以你有了:

var image = new google.maps.MarkerImage('<?php bloginfo('template_directory'); ?>/img/marker.png',
    new google.maps.Size(60,78),
    new google.maps.Point(0,0),
    new google.maps.Point(30,78)
);
var shadow = new google.maps.MarkerImage('<?php bloginfo('template_directory'); ?>/img/marker-shadow.png',
    new google.maps.Size(105,78),
    new google.maps.Point(0,0),
    new google.maps.Point(30,78)
);
于 2012-10-26T15:59:25.673 回答