谷歌地图api v3没有显示

时间:2013-06-24 13:23:32

标签: php html google-maps

我想在我的网页上显示谷歌地图,但它没有显示在我的网页上,我无法修复错误是什么,我尝试了不同的方法,但仍然地图区域看起来空白...所以请帮我解决错误....对不起我的英文

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&key=AIzaSyA39kFEuPToMAHcpdQzzpZFmpyENv9MT_A&sensor=false"></script>
    <script>
var map;
function initialize() {
  var mapOptions = {
    zoom: 8,
    center: new google.maps.LatLng(-34.397, 150.644),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);
}

google.maps.event.addDomListener(window, 'load', initialize);

    </script>
<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post" onSubmit="return check_add_form();">
<table width="100%" border="0" class="details">
  <tr>
    <th colspan="2" align="left" nowrap="nowrap" class="top-heading">Map Location</th>
    </tr>
  <tr>
    <th width="22%" align="left" valign="top" nowrap="nowrap" class="heading">Address: </th>
    <td width="78%" align="left" valign="top"> <input type="text" id="Location_Address" name="Location_Address" value="<?php echo stripslashes($Location_Address);?>"/>
      <span class="red">*</span></td>
  </tr>
  <tr>
    <td colspan="2" align="left" valign="top" nowrap="nowrap">
    <input type="hidden" id="Latitude" name="Latitude" value="<?php echo stripslashes($Latitude);?>"/>
    <input type="hidden" id="Longitude" name="Longitude" value="<?php echo stripslashes($Longitude);?>"/>
    <div id="map-canvas"></div>
    </td>
    </tr>
  <tr>
    <th  nowrap="nowrap"></th><td align="left" valign="top"><span id="message" class="red"><?php echo $message;?></span><br />
      <input type="submit" name="submit" value="Save"/></td>
  </tr>
</table>
<div id="googleMap" style="width:500px;height:380px;"></div>
</form>
`

提前感谢....

1 个答案:

答案 0 :(得分:2)

在文档的头部使用以下代码

    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&key=AIzaSyA39kFEuPToMAHcpdQzzpZFmpyENv9MT_A&sensor=false"></script>
        <script>
    var map;
    function initialize() {
      var mapOptions = {
        zoom: 8,
        center: new google.maps.LatLng(-34.397, 150.644),
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      map = new google.maps.Map(document.getElementById('map-canvas'),
          mapOptions);
    }

    google.maps.event.addDomListener(window, 'load', initialize);

</script>

并使用

<div id="googleMap" style="width:500px;height:380px;"></div>

在您的文件的任何地方

相关问题