2012-09-26 75 views
0

我设法实现Google Maps Api,并通过函数从Wordpress数据库加载标记。但我无法弄清楚如何将自定义图标添加到标记引脚。问题在于Wordpress不允许直接访问模板文件。Google Maps API标记,Wordpress和jQuery

我的形象在主题加载/ THEMENAME/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 
        }); 
+0

您没有阅读过Google Maps API文档吗? – trickyzter

+0

我已阅读过多次。没有关于wordpress或php加载标记图标的规范。或者我可能还没有找到它...... –

+0

为什么Google Maps API v3文档会提到关于wordpress或PHP的任何内容?它确实告诉你如何实现[自定义标记图标](https://developers.google.com/maps/documentation/javascript/overlays#SimpleIcons)。 – geocodezip

回答

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) 
);