简体   繁体   English

使Google Maps Marker在所有视口中居中

[英]keeping Google Maps Marker Centered in all viewports

Not even sure if the following is possible, haven't found anything yet to confirm either way on the net so far 甚至不确定是否可以进行以下操作,到目前为止尚未找到任何方法可以在网上确认任何一种方法

I am using this to display my map 我正在用它来显示我的地图

<iframe width="100%" height="100%" frameborder="0" scrolling="no" marginheight="0"     marginwidth="0" src="https://maps.google.co.uk/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=NP19+7GA&amp;aq=&amp;sll=52.405331,-4.159948&amp;sspn=5.732167,16.907959&amp;ie=UTF8&amp;hq=&amp;hnear=NP19+7GA,+United+Kingdom&amp;ll=51.595904,-2.979781&amp;spn=0.011397,0.033023&amp;t=m&amp;z=14&amp;iwloc=near&amp;output=embed"></iframe>

It is taken off the google maps webpage as you can probably tell. 如您所知,它已从Google Maps网页上删除。 So far it fills 100% of the screen, which is fine but I am implementing in a responsive website and was wondering if when changing the size of the viewport the marker that is generated can stay centered. 到目前为止,它占满了屏幕的100%,这很好,但是我正在响应式网站中实施该应用,并且想知道在更改视口大小时,生成的标记是否可以保持居中。

at the moment the map shrinks as the viewport does but you lose sight of the marker (location) 此刻地图会像视口一样缩小,但是您看不到标记(位置)

EDIT 编辑

If I use the google maps api V3 i can add an event listener like so 如果我使用Google Maps API V3,则可以添加事件监听器,如下所示

google.maps.event.addDomListener(window, 'resize', function() {
map.setCenter(homeLatlng);
}); 

Is there a way in Jquery to create this function? 有没有一种方法可以在Jquery中创建此功能?

jQuery is javascript, as is the GMaps API. jQuery和GMaps API一样都是JavaScript。 Just put the code above in with your other js. 只需将上面的代码与您的其他js一起放入即可。

You could rewrite it to use a jQuery event, but there would be no benefit in doing so. 您可以重写它以使用jQuery事件,但是这样做没有任何好处。

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

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