Twitter Bootstrap & Google Maps

前端 未结 2 1560
[愿得一人]
[愿得一人] 2021-02-01 23:38

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 bet

相关标签:
2条回答
  • 2021-02-01 23:52

    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();
               });
        });
    

    0 讨论(0)
  • 2021-02-02 00:01

    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();
    
    0 讨论(0)
提交回复
热议问题