-1

我有数百篇带有地址自定义字段的帖子,有时该字段是摘录。我根据自定义帖子类型从这些字段中提取地址,以便对其进行整理。然后我希望在functions.php中创建一个函数,我可以将此地址传递给并生成地图。

我环顾四周,并尝试了以下代码,但它仅适用于 Chrome,我做错了什么?它在 FF 和 IE 中不起作用。

function make_map($address) {

    $google_api_key = 'API';

    if($address): ?>
    <script src="http://maps.google.com/maps?file=api&amp;v=3&amp;sensor=false&amp;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;
}
4

1 回答 1

2

这不应该在任何浏览器中工作。您使用的是 Google Maps API v2 语法,但包括 Google Maps API v3。

请注意,Google Maps API v2 已弃用,可能会在 2013 年 5 月停止工作。

于 2012-09-18T09:35:14.090 回答