开发者

How do I trigger Google Maps API methods using gMap jQuery plugin?

开发者 https://www.devze.com 2023-02-10 15:54 出处:网络
I\'m using the gMap plugin for jQuery and need to call the native Google Map API\'s \"resize\" method 开发者_JAVA百科after map initialisation.Can anyone tell me how I\'d achieve that?

I'm using the gMap plugin for jQuery and need to call the native Google Map API's "resize" method 开发者_JAVA百科after map initialisation. Can anyone tell me how I'd achieve that?

I'm initialising my map element this way, as per the gMap plugin documentation:

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

The tab that the map appears in is initially hidden, which I know causes draw problems for the Google Maps API (and subsequently many of us web developers it seems).

I've tried setting the map init every time the tab is shown, but this causes flicker and also causes the map display to reset to its default state--neither of which are acceptable, unfortunately.

So, triggering the API's "resize" method via gMaps; I've tried the following when showing the tab's content, but none of them work:

$('#myMap').resize();

$('#myMap').gMap(resize);

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

$(window).resize();

I've tried asking for help from the gMap Twitter account, but it seems to have been abandoned.

I'd really appreciate a better brain than mine explaining how I can call GMap methods when using the gMap plugin for jQuery.


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


The gMap plugin seems to use v2 of the API. So calling google.maps.event.trigger won't work.

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

Otherwise, I would strongly suggest not bothering with any wrapper libraries. They do not provide much benefit, and as you can see - they make it hard to access important features of the Maps API.


OK, I think I'll switch to v3 of the native Google Maps API and carry on from there.

In gMaps defence, whilst it doesn't add functionality, it does simplify setting up the map and adding markers to it. Which is why it intrigued me in the first place.

Thanks for the feeback.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号