Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Adding info window in JQuery(customizing googlemaps)

I have no idea what I'm doing wrong. Here's the question "On the next line, in app.js, use "google.maps.event.addListener()" with "marker" as the first argument, "click" as the second, and then an anonymous function as the third."

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);
var markers = new Array();

var geocoder = new google.maps.Geocoder();
var bounds = new google.maps.LatLngBounds();

var geocoderOptions = {address: "Magic Kingdom, Disney World"};

var markerImage;
var infoWindow;

geocoder.geocode(
    geocoderOptions,
    function(results, status) {
        if(status == google.maps.GeocoderStatus.OK) {
            var marker = new google.maps.Marker({map: theMap, position: results[0].geometry.location});
            markers.push(marker);
            bounds.extend(results[0].geometry.location);
            theMap.fitBounds(bounds);
      infoWindow = new google.maps.InfoWindow({content: "Magic Kingdom"});
      google.maps.event.addListener(marker, click, function(){})

        }
    }
)

5 Answers

Chase Lee
Chase Lee
29,275 Points

Your lines of code should be right after:

var marker

Also:

click

In:

 google.maps.event.addListener(marker, click, function(){})

Should be a string, last try putting a semi colon at the end of:

 google.maps.event.addListener(marker, click, function(){})

Hope that helps.

Merry Christmas! Can you help me with this I'm not following where the code is supposed to be. I'm in 2/3 http://codepen.io/AcesUp/pen/spnrl

I have this and cannot proceed:

  var infoWindow = new google.maps.InfoWindow({content: "Magic Kingdom"});
  google.maps.event.addListener(marker, "click", function(){
  infoWindow.open(map, marker)
  });

http://codepen.io/AcesUp/pen/jpEdc

Michael Aguilera
Michael Aguilera
19,379 Points

You do not need the infoWindow.open(map, marker) ...check to see if you have it on line 17, it should be on line 27.

You need theMap instead of map in your infoWindow.

Juliano Vargas
PLUS
Juliano Vargas
Courses Plus Student 15,575 Points

google.maps.event.addListener(marker, "click", function(){}); on line 23