0
我使用Wordpress,併成功地在使用GMaps的多個標記在我的網站上顯示地圖。不幸的是,我希望將「位置名稱」超鏈接到我網站上的相關帖子。不過,出於某種原因,我無法在不崩潰整個地圖的情況下向infowindow添加超鏈接。使用GMaps爲Infowindow添加超鏈接
下面是功能代碼,只要我刪除strip_tags();
函數,地圖不再顯示。我猜這與"
太多有關,但我無法弄清楚如何讓它工作。
$str = '';
foreach($loop as $p){
//get the meta and taxonomy data
$name = strip_tags(get_the_term_list($p, "mountains"));
$wtr_long = get_post_meta($p,"wtr_longitude",true);
$wtr_lat = get_post_meta($p,"wtr_latitude",true);
//Add to Array
$map_string .= '{latitude: "' . $wtr_lat . '", longitude: "' . $wtr_long . '", html: "' . $name .'"},~!~';
//$map_string .= '{latitude: "' . $wtr_lat . '", longitude: "' . $wtr_long . '", html: "name"},~!~';
}
//Remove last three "~!~" characters from the string not to have one too many arrays when exploding
$clean_map_string = substr($map_string, 0, -3);
//Now I can use explode on ~!~ to get arrays with my string
$map_array = explode('~!~', $clean_map_string);
?>
<!--Map implementation-->
<div id="map" style="width:880px; height: 600px; background-color:grey;"></div>
<script type="text/JavaScript">
$("#map").gMap({
scrollwheel: false,
maptype: G_PHYSICAL_MAP,
markers: [
<?php
$i = 0;
$length = count($map_array)-1;
//Inserts all the markers
foreach($map_array as $value){
if($i != $length){
echo $value;
}
else {
echo str_replace("},", "}],", $value);
}
$i++;
}
?>
popup: false,
zoom: 2 });
</script>
感謝您的幫助@ Dr.Molle。 這就像一個魅力!你在變量中轉換經度和緯度,這可能是我必須做的最簡單的修復。 – WouterB 2012-03-15 13:56:40
哦,對不起,現在是固定的 – 2012-03-15 14:00:21