Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap & Google Maps

I have a navbar and 100% x 100% google map in my app. I would like to add a sidebar on the right with different filters. Reason for adding it on the right side is because of better experience on smaller screens as the right content is pushed below.

The map renders full screen with fluid (%) values when I just add the map after the last nav bar div, like this:

Map is visible:

<div class="navbar">
    <nav bar stuff......>
</div>
<div id="map-canvas"></div>

Map is not visible if I try to add it inside a span to control the size of it and add a side bar.

<div class="container-fluid">
    <div class="row-fluid">
        <div class="span9">
            <div id="map-canvas"></div>
        </div>
        <div class="span3">
            <div class="well sidebar-nav">
                <ul class="nav nav-list">
                    <li class="nav-header">Sidebar</li>
                    <li class="active"><a href="#">Link</a></li>
                    <li><a href="#">Link</a></li>
                    <li><a href="#">Link</a></li>
                </ul>
            </div>
        </div>
    </div>
</div>

I don't want to add a fixed value to the map, since it defeats the purpose of fluid.

Thanks in advance for any tips on how I can make the map visible inside a container-fluid.

like image 859
Epalissad Avatar asked Mar 09 '12 12:03

Epalissad


People also ask

What is twitter bootstrap used for?

Twitter Bootstrap is a front end framework to develop web apps and sites fast. In modern web development, there are several components which are required in almost all web projects. Bootstrap provides you with all those basic modules - Grid, Typography, Tables, Forms, Buttons, and Responsiveness.

Is twitter bootstrap the same as Bootstrap?

There's no difference. Twitter Bootstrap was the official name for version 1.0 (Twitter Bootstrap). Later the name has been shortened.

Does Twitter make Bootstrap?

Bootstrap, originally named Twitter Blueprint, was developed by Mark Otto and Jacob Thornton at Twitter as a framework to encourage consistency across internal tools.

Is twitter bootstrap still relevant?

Fast forward to nearly a decade later. With the rise of JavaScript front-end frameworks and an ever-changing landscape of technology and tools, a lot of folks are out there asking if Bootstrap is still relevant in 2021. The short answer is yes.


2 Answers

Posted the answer I found as comment before, but to make it more visible, here is the answer: https://github.com/twbs/bootstrap/issues/2475

You must add a javascript callback that will manually set the height of the map-canvas when the window is resized, for example.

$(window).resize(function () {
    var h = $(window).height(),
        offsetTop = 60; // Calculate the top offset

    $('#map-canvas').css('height', (h - offsetTop));
}).resize();
like image 166
Epalissad Avatar answered Sep 28 '22 09:09

Epalissad


I have done it already.

First time I try with same as your problem. A GPS map in bootstrap content-tab. And I just load or initial map with tab click event by something like this.

var map = undefined;
var marker = undefined;
var position = [13.821805500000002, 100.84968549999999];
var latlng;

function initialize() {

    latlng = new google.maps.LatLng(position[0], position[1]);
    var myOptions = {
        zoom: 11,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    marker = new google.maps.Marker({
        position: latlng,
        map: map,
        draggable: true,
        title: "Your current location!"
    });

    google.maps.event.addListener(marker, 'drag', function() {
        $('#txtlat').val(marker.position.lat());
        $('#txtlng').val(marker.position.lng());
    }
    );
}

    $(document).ready(function() {
          $("div.tabbable ul.nav  a[href=#gps_tab]").bind('click', function() {
                  initialize();
                 $("#map_canvas").show();
           });
    });

like image 39
TJKing Avatar answered Sep 28 '22 09:09

TJKing