简体   繁体   English

放置在div内的Google地图不在位置

[英]Google map out of position when placed inside div

Two important facts: 两个重要事实:

  1. This is what I mean by 'out of position': 这就是我所说的“不合适”:

在此输入图像描述

  1. The div in question initially has style="display:none;" 有问题的div最初有style="display:none;" (it only shows when a link is clicked, JQuery solution). (它仅在单击链接时显示,JQuery解决方案)。 When that style is removed, the map works fine - however, I need that style because I can't allow that di> to show until the link is clicked (one of the links on the left in the screencap). 当删除该样式时,地图工作正常 - 但是,我需要这种样式,因为我不能允许显示di>直到单击链接(屏幕截图左侧的一个链接)。

Can anyone suggest a way to make the map show properly? 任何人都可以建议一种方法来使地图正确显示?

If not, maybe you can suggest a way to make the di> show/hide when the links are clicked without having that style? 如果没有,也许你可以建议一种方法,在没有这种风格的情况下点击链接时显示/隐藏di> show / hide? Note that it is only one of seven divs that show/hide in the same way, so a solution would have to take that into account. 请注意,它只是以相同方式显示/隐藏的七个div之一,因此解决方案必须考虑到这一点。 This is the jQuery I'm using for each div (shows that div when link is clicked and hides all the others): 这是我为每个div使用的jQuery(在单击链接时显示div并隐藏所有其他div):

    <script type="text/javascript"> 
   $(function() {
       $('#show_mapa').click(function() {
           $('#mapa').show();
           $('#podaci').hide();
           $('#udaljenosti').hide();
           $('#pojedinosti').hide();
           $('#slika').hide();
           $('#slike').hide();
           $('#dodaj').hide();
           return false;
       });        
   });
</script>

When you initialize a google map inside a hidden div, this happens. 当您在隐藏的div中初始化谷歌地图时,会发生这种情况。 You need to call a method on the map object after showing it to make it display correctly (onResize()). 您需要在显示地图对象后调用方法以使其正确显示(onResize())。

how to deal with google map inside of a hidden div (Updated picture) 如何处理隐藏div内的谷歌地图(更新图片)

this might be of help. 这可能会有所帮助。

I remember I had the same problem and actually used the same fix danp suggested that is found here: how to deal with google map inside of a hidden div (Updated picture) 我记得我有同样的问题,实际上使用相同的修复danp建议在这里找到: 如何处理隐藏div内的谷歌地图(更新图片)

This is an alternative: You can always add a listener to observe a click on a link, that's called "Show me the map" or something. 这是另一种选择:你总是可以添加一个监听器来观察链接上的点击,这就是所谓的“给我看地图”等等。 Then when the link is clicked, only then load a google map within a seperate div. 然后,当点击链接时,只在一个单独的div中加载谷歌地图。

Personally I like the show/hide way much better with the onResize() fix, but you can try the alternative if you want. 我个人喜欢使用onResize()修复更好的显示/隐藏方式,但如果你愿意,可以试试替代方案。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM