Gmaps4rails shows marker right after map when map is inside tab

I am using Gmaps4rails and I managed to get it to work inside a tab by adding this code to the tab functionality.

$(function() {
        $( "#tabs" ).tabs({
                        fx: { opacity: 'toggle' },
                        select: function(event, ui) {
                                jQuery(this).css('height', jQuery(this).height());
                                jQuery(this).css('overflow', 'hidden');
                        },
                        show: function(event, ui) {
                                jQuery(this).css('height', 'auto');
                                jQuery(this).css('overflow', 'visible');
                                google.maps.event.trigger(map, 'resize');
                        }

                });

      

http://hik-fyp.heroku.com/en/events/31

As you can see in this example (scroll down and click the Map tab) the map looks great, but the marker is very close to the top left corner. The marker is in the correct position, the map is not the center.

Any idea why?

+3


source to share


1 answer


if it's just a map marker:

var lat = Gmaps.map.markers[0].lat;
var lng = Gmaps.map.markers[0].lng;
var centerpoint = new google.maps.LatLng(lat, lng);
Gmaps.map.map.setCenter(centerpoint);

      



it is advisable that you can give these cords when creating a marker

0


source







All Articles