如何在 Javascript 中调整 Google 地图信息窗口的大小(v3 API)

发布于 2025-01-02 06:21:52 字数 2257 浏览 2 评论 0原文

是的。这是 Google Maps API v3:InfoWindow 大小调整不正确。
但是,针对该问题提供的解决方案都不适合我:(

代码:

 //after getting a 'position' object:
 var mapPos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
 var mapOptions = { zoom:16, center:mapPos,mapTypeId:google.maps.MapTypeId.ROADMAP };
 var yourLocationMap = new google.maps.Map(document.getElementById('locationMap'), mapOptions);

 var infoContent = '<div style="width:40px;height:20px;">some information content...</div>';
 var infoBaloon = new google.maps.InfoWindow({position:mapPos, content:infoContent, maxWidth:40});
 infoBaloon.open(yourLocationMap);

这是 Google 地图为地图顶部的信息窗口创建的 HTML:

<div style="width: 247px; height: 88px;"> //<-This is actually the size of the info
window. I have no idea on what basis it decides on these dimensions.

     //next is the div for the 'X'(close) button:
    <div style="width: 10px; height: 10px; overflow: hidden; position: absolute; opacity: 0.7; left: 12px; top: 12px; z-index: 10000; cursor: pointer;">
        <img src="http://maps.gstatic.com/mapfiles/mv/imgs8.png" style="position: absolute; left: -18px; top: -44px; width: 68px; height: 67px; -moz-user-select: none; border: 0px none; padding: 0px; margin: 0px;"></div><div style="cursor: default; position: absolute; right: 18px; top: 18px; z-index: 2; overflow: auto; width: 213px; height: 54px;">
    </div>

    // I don't know where this div is coming from... :\
    <div style="cursor: default; position: absolute; right: 18px; top: 18px; z-index: 2; overflow: auto; width: 213px; height: 54px;">
       <div style="overflow: auto;">

           **// and then, finally, the div I put in the Content of the InfoWindow:
           <div style="width:40px;height:20px;">Some content information...</div>**
       </div>
   </div>
</div>


嗯,帮忙?


注意:#locationMap div 具有其大小样式(不包含在代码示例中)。 地图的表示没有问题 - 只是 InfoWindow 的表示似乎总是 247px 宽,无论我将其内容设置为什么......

Yes. This is a duplicate of Google Maps API v3: InfoWindow not sizing correctly.
However, none of the solutions offered on that question worked for me :(

code:

 //after getting a 'position' object:
 var mapPos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
 var mapOptions = { zoom:16, center:mapPos,mapTypeId:google.maps.MapTypeId.ROADMAP };
 var yourLocationMap = new google.maps.Map(document.getElementById('locationMap'), mapOptions);

 var infoContent = '<div style="width:40px;height:20px;">some information content...</div>';
 var infoBaloon = new google.maps.InfoWindow({position:mapPos, content:infoContent, maxWidth:40});
 infoBaloon.open(yourLocationMap);

This is the HTML Google Maps creates for the info-window on top of the map:

<div style="width: 247px; height: 88px;"> //<-This is actually the size of the info
window. I have no idea on what basis it decides on these dimensions.

     //next is the div for the 'X'(close) button:
    <div style="width: 10px; height: 10px; overflow: hidden; position: absolute; opacity: 0.7; left: 12px; top: 12px; z-index: 10000; cursor: pointer;">
        <img src="http://maps.gstatic.com/mapfiles/mv/imgs8.png" style="position: absolute; left: -18px; top: -44px; width: 68px; height: 67px; -moz-user-select: none; border: 0px none; padding: 0px; margin: 0px;"></div><div style="cursor: default; position: absolute; right: 18px; top: 18px; z-index: 2; overflow: auto; width: 213px; height: 54px;">
    </div>

    // I don't know where this div is coming from... :\
    <div style="cursor: default; position: absolute; right: 18px; top: 18px; z-index: 2; overflow: auto; width: 213px; height: 54px;">
       <div style="overflow: auto;">

           **// and then, finally, the div I put in the Content of the InfoWindow:
           <div style="width:40px;height:20px;">Some content information...</div>**
       </div>
   </div>
</div>

Um, help?

NOTE: the #locationMap div has stylings for its size (not included in the code example).
There are no problems in the representation of the map - just the representation of the InfoWindow which always seem to be 247px wide, no matter what I set its content to...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半夏半凉 2025-01-09 06:21:52

不确定它是否有帮助,但我发现实际上有两件事可以控制谷歌地图中信息窗口的高度。

  1. infoWindow 的内容和适用于 infoWindow 内容的 CSS(大多数人都清楚这一点)
  2. (以及可能最令人困惑的)谷歌地图画布本身的高度!

我有一个画布,高度设置为 250 像素,无论我如何设计要放置在信息窗口中的内容的样式,它仍然保持 88 像素的固定高度,并且会出现滚动条。一旦我将画布放大一点(300px),信息窗口的最大高度也发生了变化。

如果您认为调整信息窗口大小方面的其他操作都正确,那么最后的办法就是使画布更大一些。

祝你好运!

not sure if it helps but I found that there are actually 2 things that control the height of the infoWindow in google maps.

  1. The contents of the infoWindow and the CSS that applies to the contents of infoWindow (most people are well aware of this)
  2. (and what may be most confusing) the height of the google maps canvas itself!!!

I had a canvas that was set to 250px tall and regardless of how I styled the content that was to be placed in the infoWindow, it remained a fixed height of 88px and a scrollbar appear. Once I made the canvas a little larger (300px) the max-height of the infoWindow also changed.

If you think you are doing everything else right with sizing your infoWindow, the last resort is to make your canvas a little larger.

best of luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文