Adding Hyperlinks to Infowindow using GMaps
我正在使用 WordPress,并且成功地在我的网站上使用 GMaps 显示了带有多个标记的地图。不幸的是,我希望将"位置名称"超链接到我网站上的相关帖子。但由于某种原因,我无法在不破坏整个地图的情况下向信息窗口添加超链接。
下面是功能代码,只要我删除
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | $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--> <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 }); |
InfoWindows 通常对标签没有问题。您正在尝试在那里创建一个 JSON 字符串,使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <?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--> <script type="text/JavaScript"> $("#map").gMap({ scrollwheel: false, maptype: G_PHYSICAL_MAP, markers: <?php echo json_encode($markers);?>, popup: false, zoom: 2 }); |