通过PHP嵌入Google Map包括声明

时间:2015-02-06 14:34:58

标签: php google-maps php-include

我创建了一个自定义谷歌地图来显示我的业务分支(存储在名为[map-locations] .php的文件中。

当我在浏览器中打开此文件时,文件显示完美,但是如果我尝试使用include语句包含此php文件,则根本不显示该文件。

我试图将代码直接复制并粘贴到我网站上的页面中,我想要显示代码,但它也没有显示。

我宁愿能够通过include语句显示地图,但是现在只是为了显示它会很棒!

    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      .wrap { max-width: 75em; min-height: 40em; height:600px; width:500px;   margin: 0 auto; padding-top: 2.5%;}
      #map-canvas { height: 90%; }
    </style>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true">
    </script>
    <script type="text/javascript">
      var map;
      var centerPos = new google.maps.LatLng(51.6491587,0.0386048);
      var zoomLevel = 11;


      function LogoControl(controlDiv, map) { 
  controlDiv.style.padding = '5px';
  var controlUI = document.createElement('div');
  controlUI.style.backgroundImage = 'url(http://www.1stopinstruction.com/media/images/logos/1stop/googlemap-title.gif)';
  controlUI.style.width = '275px';
  controlUI.style.height = '65px';
  controlUI.style.cursor = 'pointer';
  controlUI.title = 'Click to set the map to Home';
  controlDiv.appendChild(controlUI);
  google.maps.event.addDomListener(controlUI, 'click', function() {
    map.setCenter(centerPos)
    map.setZoom(zoomLevel)
  });

}

      function initialize() {
        var mapOptions = {
          center: centerPos,
          zoom: zoomLevel
        };
        map = new google.maps.Map( document.getElementById("map-canvas"), mapOptions );
            var locations = [
  ['East London - Ilford (Fairlop Powerleague)', 51.598589, 0.101594],
  ['North London - Tottenham (Frederick Knight Sports Ground)',51.607052, -0.054270],
  ['Highams Park - Chingford (LGV & PCV Only)',51.609685, -0.005183],
  ['North Weald Airfield (kneedown & Wheelie Only)',51.717709, 0.160214],
  ['Office Address',51.572126, 0.106147]
]
var image = "http://www.1stopinstruction.com/media/images/logos/1stop/googlemap-icon.gif";

 logoControlDiv = document.createElement('div');
var logoControl = new LogoControl(logoControlDiv, map);

logoControlDiv.index = 1;
map.controls[google.maps.ControlPosition.TOP_CENTER].push(logoControlDiv);


for (i = 0; i < locations.length; i++) {  
  marker = new google.maps.Marker({
    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    title: locations[i][0],
    map: map,
    icon: image
  });
}
      }
      google.maps.event.addDomListener(window, 'load', initialize);
    </script>

  <body>
  <div class="wrap">
    <div id="map-canvas"></div>
  </div>
  </body>

1 个答案:

答案 0 :(得分:0)

问题是你的javascript代码是在DOM完全充电之前执行的。将您的javascript代码放在<div class="wrap">...</div>之后但在body代码

内的文档底部