Tuesday, November 1, 2011

Tabbed infowindow in Google Map V3

This article will show you how to create a tabbed infowindow in Google Map V3
First, download the css and js script file. Download here
Then, putting it in your project and referring it in your html code.

<link type="text/css" href="/CSS/jquery-ui.css" rel="stylesheet" />
<link type="text/css" href="/CSS/thickbox.css" rel="stylesheet" />
<script type="text/javascript" src="/SCRIPT/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/SCRIPT/jquery-ui.min.js"></script>

Like the previous post, we have to define the location, map option, maker:
        var latlng = new google.maps.LatLng(10.823099, 106.629664);
        var myOptions =
        {
            zoom: 12,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

        var marker = new google.maps.Marker({
            position: new google.maps.LatLng(10.823099, 106.629664),
            map: map
        });

Next, we define the content of the infowinow:
var text1 = [
          '<div id="InfoText">',
          '<div class="tabs"><ul><li><a href="#tab1">Details</a></li>',
          '<li><a href="#tab2" id="SV">Picture</a></li></ul>',
          '<div id="tab1">',
          '<ul>',
            '<li>Company name: ABC</li>',
            '<li>Address: 130 Truong Chinh</li>',
            '<li>City: Ho Chi Minh</li>',
            '<li>Country: Vietnam</li>',
          '</ul>',
          '</div>',
          '<div id="tab2">',
          '<p><center><a class="thickbox" href="/Images/Lighthouse.jpg"><img src="Images/Lighthouse.jpg" width="120" height="80"></a></center></p>',
          '</div>',
          '</div>'
        ].join('');



You can see in the code above I had 2 tabs for the infowindow, one for Details and the other for Picture.
Then, define the infowindow and call it when the user clicks on the marker:

 var infowindow = new google.maps.InfoWindow();

google.maps.event.addListener(marker1, "click", function () {
            //             if (infowindow) infowindow.close();
            infowindow.setContent(text1);
            infowindow.open(map, marker1);
            $(".tabs").tabs();
            tb_init('a.thickbox');

        });

The figure bellow shows our result



 
Hope this helps!


Read more:

Displaying jquery popup when clicking on an image link in infowindow
Working with a simple infowindow in google map
Adding a tooltip to marker
Add markers to Google Maps
Embedding a google map to the web page

1 comments:

AlVer said...

Hello
Could you put the full code? the css code included...
Thank you very much...

PD: sorry for my English

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Affiliate Network Reviews