Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Tom Checkley
Tom Checkley
25,181 Points

google map not rendering properly unless screen is resized

I have a google map that comes up in a pop up box, it's not rendering properly unless the screen is resized. I've looked at the stack overflow replies and none seem to work or make much sense! The site I'm making has various break points and isn't user scalable so i need a way to make it load properly without resizing the screen. This is what i have so far-

function initialize() {
    var map_canvas = document.getElementById('map_canvas');
    var myLatLong = new google.maps.LatLng(51.461112, -2.602336);
    var map_options = {
      center: myLatLong,
      center: myLatLong,
      zoom: 17,
      mapTypeId: google.maps.MapTypeId.ROADMAP
     }
    map = new google.maps.Map(map_canvas, map_options)
    var marker = new google.maps.Marker({
        position: myLatLong,
        map: map,
        title: 'Stephen Sheppard'
     });
}

google.maps.event.addDomListener(window, 'load', initialize);

I found this on stack overflow annd have tried to use it but its doesn't seem to work either

//open location map resize
    $('.location').on('click',function(){
        google.maps.event.trigger(map, 'resize');
        google.maps.event.trigger($('#location'), 'resize');
        console.log('resize should happen')
    });