我有数百篇带有地址自定义字段的帖子,有时该字段是摘录。我根据自定义帖子类型从这些字段中提取地址,以便对其进行整理。然后我希望在functions.php中创建一个函数,我可以将此地址传递给并生成地图。
我环顾四周,并尝试了以下代码,但它仅适用于 Chrome,我做错了什么?它在 FF 和 IE 中不起作用。
function make_map($address) {
$google_api_key = 'API';
if($address): ?>
<script src="http://maps.google.com/maps?file=api&v=3&sensor=false&key=<?php echo $google_api_key; ?>" type="text/javascript"></script>
<div id="map_canvas" style="width: 250px; height: 250px"></div>
<script type="text/javascript">
function showAddress(address)
{
var map = new GMap2(document.getElementById("map_canvas"));
var geocoder = new GClientGeocoder();
geocoder.getLatLng(
address,
function(point)
{
if (!point)
{
alert(address + " not found");
}
else
{
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
}
}
);
}
showAddress("<?php echo $address; ?>");
</script>
<br>
<?php endif;
}