google地图标记未定义wordpress

google地图标记未定义wordpress,wordpress,google-maps,Wordpress,Google Maps,我正在使用下面的最后通牒WordPress主题模板中的代码以及一些PHP代码来提供地图所需的动态值。我得到一个未定义的标记错误。代码被放置在div标记中,而不是页眉或页脚中,因为它只在一个页面上使用。我尝试了几条建议,但都没有成功 <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script> <script type="text/j

我正在使用下面的最后通牒WordPress主题模板中的代码以及一些PHP代码来提供地图所需的动态值。我得到一个未定义的标记错误。代码被放置在div标记中,而不是页眉或页脚中,因为它只在一个页面上使用。我尝试了几条建议,但都没有成功

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
//<![CDATA[
var geocoder;
var map;
function initialize ()
{
    geocoder = new google.maps.Geocoder();
    var address = document.getElementById('Property').value;
    var city = document.getElementById('City').value;
    var postal_code = document.getElementById('PostalCode').value;
    var address_google_map = address + ', ' + city + ', ON ' + postal_code;

    var myOptions =
    {
        zoom: 15,
        mapTypeControl: true,
        zoomControl: true,
        zoomControlOptions:
        {
            style: google.maps.ZoomControlStyle.SMALL
        },
        StreetViewControl: false,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var info_text = address + '<br />' + city + ' ON';
    var info_window = new google.maps.InfoWindow
    ({
        content: info_text
    });
    var map = new google.maps.Map(document.getElementById('google_map'), myOptions);

    geocoder.geocode( { 'address': address_google_map}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
            map: map,
            position: results[0].geometry.location
        });
      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });


    google.maps.event.addListener(marker, 'click', function()
    {
        info_window.open(map, marker);
    });
}


window.onload = function() {
   initialize();
}
//]]>
</script>

//

该标记是地理编码器回调例程的本地标记。将click listener定义移动到其作用域内的函数中

geocoder.geocode( { 'address': address_google_map}, function(results, status) {
  if (status == google.maps.GeocoderStatus.OK) {
    map.setCenter(results[0].geometry.location);
    var marker = new google.maps.Marker({
        map: map,
        position: results[0].geometry.location
    });

    google.maps.event.addListener(marker, 'click', function()
    {
    info_window.open(map, marker);
    });
  } else {
    alert("Geocode was not successful for the following reason: " + status);
  }
});

}

该标记是地理编码器回调例程的本地标记。将click listener定义移动到其作用域内的函数中

geocoder.geocode( { 'address': address_google_map}, function(results, status) {
  if (status == google.maps.GeocoderStatus.OK) {
    map.setCenter(results[0].geometry.location);
    var marker = new google.maps.Marker({
        map: map,
        position: results[0].geometry.location
    });

    google.maps.event.addListener(marker, 'click', function()
    {
    info_window.open(map, marker);
    });
  } else {
    alert("Geocode was not successful for the following reason: " + status);
  }
});
}