简体   繁体   English

Google Maps setCenter在IE8中不起作用

[英]Google Maps setCenter not working in IE8

I've checked other questions on StackOverflow relating to setCenter and google maps in IE8 but none of them seem to describe the problem I'm seeing. 我已经检查了关于StackOverflow的其他 问题这些 问题与IE8中的setCenter和谷歌地图有关,但是似乎都没有描述我所遇到的问题。 My javascript code constructs map objects inside collapsible divs, and due to the implementation of google maps a resize/re-center operation is required when showing the divs. 我的JavaScript代码在可折叠的div中构造了地图对象,由于实施了Google地图,因此在显示div时需要进行大小调整/重新居中操作。

The code works fine in IE9/10, Firefox, Safari and Chrome, but doesn't work in IE8 - the resize works OK but the map is not centred, rather the marker appears at the top left, just outside the viewable area (suggesting that the setCenter call is doing nothing). 该代码在IE9 / 10,Firefox,Safari和Chrome中均能正常工作,但在IE8中则无法工作-调整大小即可,但地图并未居中,而是标记显示在左上方,就在可见区域的外面(建议) (setCenter调用什么都不做)。

Resize/center code below: 调整以下尺寸/居中代码:

var center = map.getCenter();
google.maps.event.trigger(map, 'resize');
map.setCenter(center);

Never got to the bottom of why this doesn't work under IE8. 从来没有深入了解为什么这在IE8下不起作用。 In the end I coded an unpleasant hack which detects IE8 and pans the container manually to center the map, but I'd love to replace it with something less ugly if anyone has a solution... 最后,我编写了一个令人讨厌的hack程序,它检测IE8并手动移动容器以使地图居中,但是如果有人有解决方案,我希望用不太难看的东西替换它...

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

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