作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Google map 在我的网站上显示很多兴趣点,但它实际上不起作用。最奇怪的是,在实践中,它之所以有效,是因为标记和集群工作正常,连接的 Action 也在工作,但 map 没有显示, map 区域的所有内容都是灰色的。最奇怪的是它可以在移动设备上正常工作。
HTML
<div class="container-explore">
<div class="half-col half-map">
<div class="header-map" id="map"></div>
</div>
<div class="half-col half-list">
....
</div>
</div>
JS
<script>
var center = italy;
var zoom = 6;
</script>
@if(isset($lat, $lng))
<script>
var center = {lat: {{$lat}}, lng: {{$lng}}};
var zoom = 14;
</script>
@elseif(Request::has('lat') and Request::has('lng') and Request::has('formatted_address'))
<script>
var center = {lat: {{Request::input('lat')}}, lng: {{Request::input('lng')}}};
var zoom = 14;
</script>
@endif
<script>
var markers = [];
var mapObject;
function init_map() {
var mapOptions = {
zoom: zoom,
center: new google.maps.LatLng(center),
mapTypeId: google.maps.MapTypeId.ROADMAP,
scrollwheel: false,
};
var marker;
(function(A) {
if (!Array.prototype.forEach)
A.forEach = A.forEach || function(action, that) {
for (var i = 0, l = this.length; i < l; i++)
if (i in this)
action.call(that, this[i], i, this);
};
})(Array.prototype);
mapObject = new google.maps.Map(document.getElementById('map'), mapOptions);
setTimeout(function() {
update_markers_half();
}, 1500);
mapObject.addListener('dragend', function() {
update_markers_half();
});
mapObject.addListener('zoom_changed', function() {
update_markers_half();
});
}
$(window).load(function() {
$(".container-explore").css("height", $(window).height());
init_map();
});
$(window).resize(function() {
$(".container-explore").css("height", $(window).height());
});
var geo = $("#city-search");
$(geo).geocomplete().bind("geocode:result", function(event, result){
mapObject.setCenter(result.geometry.location);
mapObject.setZoom(13);
update_markers_half();
});
$.fn.geocomplete(geo)
$(document).ready(function() {
$(".minimize-explore").click(function(e) {
e.preventDefault();
$(".container-explore-list").fadeToggle();
if($(this).children("i").attr("class") == 'icon-menu') {
$(this).children("i").attr("class", 'icon-cancel');
} else {
$(this).children("i").attr("class", 'icon-menu');
}
})
})
</script>
CSS
.container-explore {
height: 100%;
overflow: hidden;
}
.half-col {
width: 50%;
float: left;
}
.half-col.half-map {
height: 388px;
position: relative;
overflow: hidden;
height: 100%;
}
.half-col.half-list {
overflow-x: hidden;
overflow-y: auto;
height: 100%;
-webkit-overflow-scrolling: touch;
padding: 15px;
margin-top: 105px;
}
.container-explore #map {
height: 100%;
}
最佳答案
我发现了问题:
img {
max-width: 100%;
max-height: 100%;
}
我添加了
#map img {
max-width: none;
max-height: none;
}
一切正常。
关于javascript - 谷歌地图不渲染但标记/集群工作(灰色 map 区域),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33607524/
leaflet:一个开源并且对移动端友好的交互式地图 JavaScript 库 中文文档: https://leafletjs.cn/reference.html 官网(英文): ht
我是一名优秀的程序员,十分优秀!