gpt4 book ai didi

html - 谷歌地图卡在左上角 - 桌面解决方案不适用于移动设计

转载 作者:太空宇宙 更新时间:2023-11-03 23:28:23 27 4
gpt4 key购买 nike

我在使用 Google map 时遇到问题,我在隐藏的 DIV 元素内渲染 map 。即使在我移动 map 后,渲染的 map 也只显示左上角。

我发现的解决方案是等待渲染 map 和点,直到用户实际显示 map 。我通过让间隔计数器每半秒迭代一次来查看用户是否单击按钮打开/显示元素来执行此操作。

这适用于桌面浏览器,但不能解决移动浏览器的相同问题。 Angular 落仍然卡住,我不确定如何从移动 Angular 处理这个问题。

<script type="text/javascript">
var locations = [SOME DATA];

var map;
var bounds;

function initialize() {
var myLatlng = new google.maps.LatLng(0, 0);
var mapOptions = {
zoom: 5,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}

map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
bounds = new google.maps.LatLngBounds();

for (var i = 0; i < locations.length; i++) {
var entity = locations[i];
var myLatLng = new google.maps.LatLng(entity[6], entity[7]);

var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: pinBase + pin
});

if(entity[8] < 5) {
bounds.extend(marker.position);
}

var infowindow = new google.maps.InfoWindow({});

if(entity[5] == "0") {
entity[5] = "N/A";
}

contentString = "<div class=\"mapBaloon\"><b>" + entity[0] + "</b><br />WWW: <a href=\"http://" + entity[2] + "\">http://" + entity[2] + "</a><br />City: " + entity[3] + "<br />State: " + entity[4] + "<br />Phone: " + entity[5] + "<br />Distance: " + entity[8] + " miles</div>";
bindInfoWindow(marker, map, infowindow, contentString);
}

map.fitBounds(bounds);
}

function bindInfoWindow(marker, map, infowindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(html);
infowindow.open(map, marker);
});
}

var myVar = setInterval(function() {
google.maps.event.addDomListener(window, 'load', initialize);

if($(".commArea2").is(":visible")) {
clearInterval(myVar);
google.maps.event.trigger(map, 'resize');
map.fitBounds(bounds);
}
}, 500);
</script>

最佳答案

我在移动设备上遇到了类似的问题。当div被触发显示时,我调用了initialize()函数。

$('#open_btn').bind('touchstart', function(event){
initialize();
})

关于html - 谷歌地图卡在左上角 - 桌面解决方案不适用于移动设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26063591/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com