Wordpress 使用GMAP向Infowindow添加超链接

Wordpress 使用GMAP向Infowindow添加超链接,wordpress,google-maps,google-maps-markers,infowindow,Wordpress,Google Maps,Google Maps Markers,Infowindow,我正在使用Wordpress,并且成功地在我的网站上显示了一张地图,上面有多个使用GMAP的标记。不幸的是,我希望将“地点名称”超链接到我网站上的相关帖子。但是由于某种原因,我无法在不破坏整个地图的情况下向信息窗口添加超链接 下面是运行代码,只要我删除strip_标签()功能地图不再显示。我猜这与有太多的“”有关,但我不知道如何让它工作 $str = ''; foreach($loop as $p){ //get the meta and taxonomy data

我正在使用Wordpress,并且成功地在我的网站上显示了一张地图,上面有多个使用GMAP的标记。不幸的是,我希望将“地点名称”超链接到我网站上的相关帖子。但是由于某种原因,我无法在不破坏整个地图的情况下向信息窗口添加超链接

下面是运行代码,只要我删除
strip_标签()功能地图不再显示。我猜这与有太多的
”有关,但我不知道如何让它工作

    $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>
$str='';
foreach($p循环){
//获取元数据和分类数据
$name=strip_标签(获取术语列表($p,“山脉”);
$wtr\u long=get\u post\u meta($p,“wtr\u经度”,true);
$wtr\u lat=get\u post\u meta($p,“wtr\u纬度”,true);
//添加到数组
$map_string.='{纬度:'.$wtr_lat.'”,经度:'.$wtr_long.'',html:'.$name.'},~!~';
//$map_string.='{纬度:'.$wtr_lat.'”,经度:'.$wtr_long.'',html:“名称”},~!~;
}
//删除最后三个“~~“字符串中的字符在分解时不能有太多数组
$clean\u map\u string=substr($map\u string,0,-3);
//现在,我可以使用explode on~!~使用字符串获取数组
$map\u数组=分解(“~!~”,$clean\u map\u字符串);
?>                        
$(“#地图”).gMap({
滚轮:错误,
地图类型:G_PHYSICAL_地图,
标记:[
弹出窗口:false,
缩放:2});

InfoWindows通常不会出现标记问题。如果要在那里创建JSON字符串,请使用
JSON\u encode()
而不是混合使用字符串函数,以避免字符串中出现无效字符

<?php
    $markers=array();
    foreach($loop as $p){

      $markers[]=array(
                        'latitude'  =>  get_post_meta($p,"wtr_latitude",true),
                        'longitude' =>  get_post_meta($p,"wtr_longitude",true),
                        'html'      =>  get_the_term_list($p, "mountains")
                      ); 
    } 

?> 
<!--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 echo json_encode($markers);?>,
                      popup: false,
                      zoom: 2 });             
</script>

$(“#地图”).gMap({
滚轮:错误,
地图类型:G_PHYSICAL_地图,
标记:,
弹出窗口:false,
缩放:2});

谢谢你的帮助@Dr.Molle。这很有魅力!你在变量中切换了经度和纬度,这可能是我做过的最简单的修复。哦,对不起,现在已经修复了