admin管理员组文章数量:1410737
I have issues loading a Google Map into a jQuery tab. I tried every single solution from the internet, using suggestions from here: Google Maps V3 not loading with jQuery tabs
Problems with Google Maps API v3 + jQuery UI Tabs
/
Google Maps and jQuery Tabs
And so on...
But none of them worked, either I'm too noob to use them and I have no idea how to add them or are not working.
This is how the tabs are shown:
<div class="tabprice">
<ul class="tabnavig">
<?php if ( $gmap_active ) { ?>
<li><a href="#block2"><span class="big"><?php _e('Map', 'anuncios') ?></span></a></li>
<?php } ?>
</ul>
<?php if ( $gmap_active ) { ?>
<!-- tab 2 -->
<div id="block2">
<div class="clr"></div>
<div class="singletab">
<?php include_once ( TEMPLATEPATH . '/includes/sidebar-gmap.php' ); ?>
</div><!-- /singletab -->
</div>
<?php } ?>
And here is the content of sidebar-gmap.php
Please guys, I beg you, help me !
I have issues loading a Google Map into a jQuery tab. I tried every single solution from the internet, using suggestions from here: Google Maps V3 not loading with jQuery tabs
Problems with Google Maps API v3 + jQuery UI Tabs
http://www.digitalwks./blogs/diogo-raminhos/google-maps-v3-and-jquery-tabs-jquery-tabs-google-maps-bug/
Google Maps and jQuery Tabs
And so on...
But none of them worked, either I'm too noob to use them and I have no idea how to add them or are not working.
This is how the tabs are shown:
<div class="tabprice">
<ul class="tabnavig">
<?php if ( $gmap_active ) { ?>
<li><a href="#block2"><span class="big"><?php _e('Map', 'anuncios') ?></span></a></li>
<?php } ?>
</ul>
<?php if ( $gmap_active ) { ?>
<!-- tab 2 -->
<div id="block2">
<div class="clr"></div>
<div class="singletab">
<?php include_once ( TEMPLATEPATH . '/includes/sidebar-gmap.php' ); ?>
</div><!-- /singletab -->
</div>
<?php } ?>
And here is the content of sidebar-gmap.php
http://pastebin./H3i4J8EN
Please guys, I beg you, help me !
Share edited May 23, 2017 at 12:21 CommunityBot 11 silver badge asked Aug 5, 2012 at 18:37 demlasjrdemlasjr 1213 silver badges13 bronze badges3 Answers
Reset to default 4I'm the author of one of the blogposts you refered.
For other persons with the same problem: The problem in here relies on the fact that you need to trigger the resize event when your show animation ends.
You can do that by calling google.maps.event.trigger(map, "resize");
on your show animation end callback.
So, in your case (for the link you sended) you need to:
Edit the following file:
/wp-content/themes/anuncios/includes/js/theme-scripts.js
And replace this:
/* Tab Control home main */
jQuery(function($) {
var tabContainers = $('div.tabcontrol > div');
tabContainers.hide().filter(':first').show();
$('div.tabcontrol ul.tabnavig a').click(function () {
tabContainers.hide();
tabContainers.filter(this.hash).fadeIn(100);
$('div.tabcontrol ul.tabnavig a').removeClass('selected');
$(this).addClass('selected');
return false;
}).filter(':first').click();
});
With this:
/* Tab Control home main */
jQuery(function($) {
var tabContainers = $('div.tabcontrol > div');
tabContainers.hide().filter(':first').show();
$('div.tabcontrol ul.tabnavig a').click(function () {
tabContainers.hide();
tabContainers.filter(this.hash).fadeIn(100, function(){
if(map != undefined && map != null)
google.maps.event.trigger(map, "resize");
});
$('div.tabcontrol ul.tabnavig a').removeClass('selected');
$(this).addClass('selected');
return false;
}).filter(':first').click();
});
Part 2
Find the following code:
$(tabs).click(function() {
// hide all tabs
$(tabContainers).hide().filter(this.hash).fadeIn(500);
$(tabs).removeClass('selected');
$(this).addClass('selected');
return false;
});
And replace it with
$(tabs).click(function() {
// hide all tabs
$(tabContainers).hide().filter(this.hash).fadeIn(500, function(){
if(map != undefined && map != null)
google.maps.event.trigger(map, "resize");
});
$(tabs).removeClass('selected');
$(this).addClass('selected');
return false;
});
And your bug will be fixed, this time I downloaded and tested it locally so I'm 100% sure it will work.
Google map need a visible and fixed canvas (div) to calculate a width and height of map in order to show it correctly. If you hide your div before, you must show it first then trigger map resize google.maps.event.trigger(map, "resize");
.
In your case, call resize in calculate() function seems ideal
function codeAddress() {
google.maps.event.trigger(map, "resize");
I have a working copy of google maps in jquery tabs here http://jsfiddle/X5r8r/529/
I used some of the code from your sources that you listed above. This is the code that does it. the other stuff is just map stuff not too important
$(document).ready(function() { //Default Action $(".tab_content").css({'visibility':'hidden' , 'position':'absolute'}); $("ul.tabs li:first").addClass("active").show(); $(".tab_content:first").css({'visibility':'visible' , 'position':'static'}); //On Click Event $("ul.tabs li").click(function() { $("ul.tabs li").removeClass("active"); $(this).addClass("active"); $(".tab_content").css({'visibility':'hidden' , 'position':'absolute'}); var activeTab = $(this).find("a").attr("href"); $(activeTab).css({'visibility':'visible' , 'position':'static'}); return false; }); });
keep in mind that this works only with the div tags i've shown in jsfiddle since I check the id
and class
tags in the divs to activate a tab. I just change the visibility of the div to hidden or visible basically.
hope this helps you out.
本文标签: javascriptLoading Google Maps in jQuery tabStack Overflow
版权声明:本文标题:javascript - Loading Google Maps in jQuery tab - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744917828a2632105.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论