English 中文(简体)
如何使用gMap jQuery插件触发谷歌地图API方法?
原标题:How do I trigger Google Maps API methods using gMap jQuery plugin?

我正在为jQuery使用gMap插件,需要在地图初始化后调用本地谷歌地图API的“调整大小”方法。有人能告诉我怎样才能做到这一点吗?

按照gMap插件文档

var defaults = {
    latitude: 0,
    longitude: 0,
    zoom: 2,
    scrollwheel: false
};
$( #myMap ).gMap(defaults);

地图出现的选项卡最初是隐藏的,我知道这会导致谷歌地图API出现问题(随后我们中的许多web开发人员也会出现问题)。

我曾尝试在每次显示选项卡时设置map init,但这会导致闪烁,也会导致map显示重置为默认状态——不幸的是,这两种情况都不可接受。

因此,通过gMaps触发API的“调整大小”方法;在显示选项卡内容时,我尝试了以下操作,但都不起作用:

$( #myMap ).resize();

$( #myMap ).gMap(resize);

google.maps.event.trigger(myMap,  resize );

$(window).resize();

我已尝试向gMap推特账户,但它似乎已被放弃。

我真的很感激有一个比我更好的大脑来解释在使用jQuery的GMap插件时如何调用GMap方法。

最佳回答

好的,我想我会切换到原生谷歌地图API的v3版本,并从那里继续。

在gMaps防御中,虽然它没有添加功能,但它确实简化了地图的设置和添加标记。这就是为什么它一开始就引起了我的兴趣。

谢谢你的反馈。

问题回答

gMap for v3 is available here: http://www.smashinglabs.pl/gmap

gMap插件似乎使用了API的v2版本。所以调用google.maps.event.trigger是行不通的。

尝试checkResize:http://code.google.com/apis/maps/documentation/javascript/v2/reference.html

否则,我强烈建议不要使用任何包装器库。它们并没有提供太多好处,正如您所见,它们使访问“地图API”的重要功能变得困难。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签