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

HTML

HTML & CSS

I have been trying to import Google Maps into my website, and I'm using a site then automatically generates the code. It offers you the height and width you would like your map. I want my map to stretch and fill 100% of its container, but I dont know what to change to make that happen within this code: html <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script><div style="overflow:hidden;height:300px;width:600px;"><div id="gmap_canvas" style="height:300px;width:600px;"></div><style>#gmap_canvas img{max-width:none!important;background:none!important}</style><a class="google-map-code" href="http://goertz-gutschein-map.com" id="get-map-data">http://goertz-gutschein-map.com</a></div><script type="text/javascript"> function init_map(){var myOptions = {zoom:15,center:new google.maps.LatLng(-28.0172605,153.4256987),mapTypeId: google.maps.MapTypeId.ROADMAP};map = new google.maps.Map(document.getElementById("gmap_canvas"), myOptions);marker = new google.maps.Marker({map: map,position: new google.maps.LatLng(-28.0172605, 153.4256987)});infowindow = new google.maps.InfoWindow({content:"<b></b><br/><br/> Gold Coast" });google.maps.event.addListener(marker, "click", function(){infowindow.open(map,marker);});infowindow.open(map,marker);}google.maps.event.addDomListener(window, 'load', init_map);</script>

2 Answers

Hi Jacob,

Generally speaking it's best to use the embed codes provided by Google Maps rather than third party applications.

Here is the one Google provides:

<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m8!1m3!1d3522.2360440052043!2d153.4256987!3d-28.017260499999995!3m2!1i1024!2i768!4f13.1!4m7!1i0!3e6!4m0!4m3!3m2!1d-28.0172605!2d153.4256987!5e0!3m2!1sen!2suk!4v1417425660065" width="600" height="450" frameborder="0" style="border:0"></iframe>

Towards the end of the script above, you can see width="600" and height="450". Use these figures to set different sizes.

There are other advanced settings, documents and tools that you can utilise for free, for example https://mapsengine.google.com/map/ or https://developers.google.com/maps/documentation/javascript/

Hope this helps!

Can i add a marker on the map so when people view the website the map is already zoomed in on a location? Thanks for the help. @Elliott Mangham

Hi Jacob,

Not to worry, I'm glad you found my answer helpful.

I presume that guidance will be on https://developers.google.com/maps/documentation/javascript/markers#add

It probably requires a little bit of Javascript adding to the page, it isn't hard to do but may require a little bit of reading :)

Kind regards