为什么我的谷歌地图没有完美加载
why my google map isn't loading perfectly?
<h4>Location</h4>
<div class="full-row mt20">
<?php
if(empty($restaurant['Restaurant']['lattitude']))
$restaurant['Restaurant']['lattitude'] = 0;
if(empty($restaurant['Restaurant']['longitude']))
$restaurant['Restaurant']['longitude'] = 0;
?>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script>
function initialize() {
var myLatlng = new google.maps.LatLng(<?php echo $restaurant['Restaurant']['lattitude']; ?>,<?php echo $restaurant['Restaurant']['longitude']; ?>);
var mapOptions = {
zoom: 6,
center: myLatlng
}
var map = new google.maps.Map(document.getElementById('googleMap'), mapOptions);
var marker=new google.maps.Marker({position:myLatlng});
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<div id="googleMap" style="height:250px;"></div>
![在此输入图像描述][1]
![在此输入图像描述][2]输出图像链接为:https://i.stack.imgur.com/YGS3X.pnghttps://i.stack.imgur.com/1SLRK.png上面的部分是我的代码和我的结果。我找不到错误。当我拖动地图时,地图的另一部分将不可见。为什么会这样?
就像@KimGyesen说的那样,您必须使用调整大小来刷新地图。试试这个代码片段,也许这对你有所帮助...
$(document).ready(function () {
var myLatlng = new google.maps.LatLng(-25.363882, 131.044922);
var mapOptions = {
zoom: 6,
center: myLatlng
}
var map = new google.maps.Map(document.getElementById('googleMap'), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng
});
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
});
setInterval(function () {
google.maps.event.trigger(map, 'resize');
map.fitBounds();
}, 2000);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<body>
<div id="googleMap" style="width:500px; height:400px"></div>
</body>
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- 如何在生成下载文件时显示加载动画
- 有没有任何方法可以将控制器从文件加载到ui路由器$stateProvider中
- 无法在通过jQuery的ajax加载的页面中执行javascript
- Emberjs应用程序加载在除Index之外的所有路由上
- 在chrome.tabs.onCreated之后加载HTML页面
- 单击F5时如何停止页面加载
- HTML5音频加载和播放获胜'我不能在iPad上工作
- 跟踪在页面加载时应用内联样式的JavaScript
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- jQuery Lazy加载动画滚动
- Html页面上的多个Base64图像和平滑加载
- 如何创建带有插槽的vue js组件预加载程序
- Webpack/Rect:遵循egghead.io教程,但出现错误:您可能需要一个合适的加载程序来处理此文件类型
- 如何使该数据在所有元素中加载
- jqgrid没有在服务器acugis中加载数据,而是在本地运行,一切都很完美
- 为什么我的谷歌地图没有完美加载
- 同位素排水沟在页面加载时不完美,但在窗口大小调整后变得完美
- 如何加载同位素布局与图像完美的位置上的差距,甚至在整个页面加载之前
- ReCaptcha不会在IE中加载/显示,但在Chrome和safari中可以完美运行