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

JQuery Google Maps Code Challenge Question

I am soo stuck on the last task in the code challenge for Adding a Dynamic Map. The task is: "Set the "theMap" to a new google.maps namespaced "Map" object with the parameters of "mapElement" and "mapOptions"

so far i have:

<script type="text/javascript">
        var mapOptions = {
    center: new google.maps.LatLng(28.42, -81.58), 
    zoom: 18,
    mapTypeId: google.maps.MapTypeId.SATELLITE,
  };

    var mapElement = document.getElementById("map");
    var theMap;

    var theMap = document.newgoogle.maps.Map(mapElement, mapOptions);
</script>

I am so lost. Please help!

12 Answers

I had a similar problem to brentmccarthy's, it turned out I had my api key script inside my map div, instead of closing the map div and adding the api script after. Once I rectified that, it no longer gave the error about task 2 no longer passing.

//I did this:
 <div id="map">
<script type="text/javascript"
  src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAn8fk75K8kCdW6pQ4B7yoBHJNrUbleieY&sensor=false"></script>
</div>

//when I should have closed the map div first like so:
<div id="map"></div>
<script type="text/javascript"
  src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAn8fk75K8kCdW6pQ4B7yoBHJNrUbleieY&sensor=false"></script>

Thanks Joseph for sharing this was exactly the issue I was having!

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

I think document.newgoogle.maps.Map should be new google.maps.Map. Also you don't need to do var theMap twice.

Regards Andrew

You need to delete the first var theMap and change document.newgoogle.maps.Map(mapElement, mapOptions); to new google.maps.Map(mapElement, mapOptions);

This is the code:

<script type="text/javascript">
    var mapOptions = {
    center: new google.maps.LatLng(28.42, -81.58),
    zoom: 18,
    mapTypeId: google.maps.MapTypeId.SATELLITE
    };

    var mapElement = document.getElementById("map");
    var theMap = new google.maps.Map(mapElement, mapOptions);
</script>

...

Thanks! Guessing the areal view at the end of this exercise is that of the Magic Kingdom at Walt Disney World Orlando (just in case anyone missed it!)

Bumpity bump bump.

Here's my code, still unable to pass.

  <div id="map">
    <script type="text/javascript"
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAn8fk75K8kCdW6pQ4B7yoBHJNrUbleieY&sensor=false">   </script>
    <script type="text/javascript">
        var mapOptions = {
        center: new google.maps.LatLng(28.42, -81.58),
        zoom: 18, 
        mapTypeId: google.maps.MapTypeId.SATELLITE
      };

        var mapElement= document.getElementById("map");
        var theMap = new google.maps.Map(mapElement, mapOptions);
    </script>
  </div>
Andrew Chalkley
Andrew Chalkley
Treehouse Guest Teacher

I saw you fixed it on the other thread! Glad you figured it out :)

Okay, I have the following code and it states that task 2 no longer passes. I am a bit stumped.

<script type="text/javascript">
    var mapOptions = {
  center: new google.maps.LatLng(28.42, -81.58),
    zoom: 18,
    mapTypeId: google.maps.MapTypeId.SATELLITE
  };
var mapElement=document.getElementById("map");
var theMap = new google.maps.Map(mapElement, mapOptions);

Yes. I tried to copy all of my code into this but it seems to get messed up. Is there a trick to this?

This is the remainder of my code.

</script></body>
Andrew Chalkley
Andrew Chalkley
Treehouse Guest Teacher

Your code worked for me. I can't see the rest of your code. This is what I have between my body tags.

 <div id="map"></div>
    <script type="text/javascript"
  src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAn8fk75K8kCdW6pQ4B7yoBHJNrUbleieY&sensor=false"></script>

    <script type="text/javascript">
         var mapOptions = {
  center: new google.maps.LatLng(28.42, -81.58),
    zoom: 18,
    mapTypeId: google.maps.MapTypeId.SATELLITE
  };
var mapElement=document.getElementById("map");
var theMap = new google.maps.Map(mapElement, mapOptions);
    </script>

Okay, that is good to know. I have windows 8 and sometimes do the development in sublime and copy it into your editor and get some pretty odd errors. Since it works on my desktop, I am pretty sure the code is correct before I copy it into your editor. Many times when I come back and try it later and it works. The only thing that I can think of is that I am picking up some hidden characters which throw off the validation of the code.

Must be the user :-)

Andrew Chalkley
Andrew Chalkley
Treehouse Guest Teacher

Windows does add some special characters to returns like \r\n rather than the plain-old \n on *nix systems like Linux and OS X.

Be sure your <div id="map"> has and end div </div>

This wasn't asked for in the beginning and so I didn't add the end tab... once I did it worked for me.

I haven't done the JQuery course yet, so I won't be much help. I did notice, that this post has a really long title, posts with titles that the reader can understand at-a-glance, are more likely to be clicked on.

A good rule of thumb for titles is between 5 to 10 words, basically short, yet descriptive