2012-09-26 139 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) 
);