现在已修复,我猜 Twitter Bootstrap CSS 必须与将高度和宽度设置为 100% 冲突。留给任何有类似问题的人。
当用户单击链接时,我正在尝试在我的网页上实现谷歌地图,所有 PHP 工作正常但由于某种原因谷歌地图没有显示,我重新阅读了 API 文档中的所有示例并重新阅读所有代码,但仍然无法正常工作,不知道为什么..
这是显示地图的页面
注意:PHP 工作正常,脚本在页面加载时加载,但地图不是。
<?php
/* Include header and config and set variable*/
require_once('config.inc.php');
require_once($rootdir . $dirsubfolder . 'navbar.php');
$route = $_GET['route'];
?>
<?php
/* User wants to retrieve their route */
if (isset($route)) {
?>
<?php
/* User wants Route 1 */
if (strcmp($route, "sunroute1") == 0) {
?>
<script type="text/javascript">
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
}
function loadScript() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.googleapis.com/maps/api/js?key=WORKINGKEYk&sensor=true&callback=initialize";
document.body.appendChild(script);
}
window.onload = loadScript;
</script>
<?php
printf('worked');
} else { printf('failed'); }
?>
<div class="container">
<div class="hero-unit">
<div id="map_canvas" style="width: 100%; height: 100%"></div>
</div>
</div>
<?php
/* End isset(route) */
}
/* Include footer */
require_once($rootdir . $dirsubfolder . 'footer.php');
?>
在我的footer.php里面我有
<script src="https://maps.googleapis.com/maps/api/js?key=MYKEYWORKING&sensor=false"></script>
这是view source
来自页面
<script type="text/javascript">
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
}
function loadScript() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.googleapis.com/maps/api/js?key=WORKING&sensor=true&callback=initialize";
document.body.appendChild(script);
}
window.onload = loadScript;
</script>
worked
<div class="container">
<div class="hero-unit">
<div id="map_canvas" style="width: 100%; height: 100%"></div>
</div>
</div>
我在页脚的脚本
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="js/bootstrap-transition.js"></script>
<script src="js/bootstrap-alert.js"></script>
<script src="js/bootstrap-modal.js"></script>
<script src="js/bootstrap-dropdown.js"></script>
<script src="js/bootstrap-scrollspy.js"></script>
<script src="js/bootstrap-tab.js"></script>
<script src="js/bootstrap-tooltip.js"></script>
<script src="js/bootstrap-popover.js"></script>
<script src="js/bootstrap-button.js"></script>
<script src="js/bootstrap-collapse.js"></script>
<script src="js/bootstrap-carousel.js"></script>
<script src="js/bootstrap-typeahead.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=WORKING&sensor=false"></script>
</body>
</html>