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
Stefan Lyew
8,448 PointsGoogle Maps Adding Info Window Quiz
For Task 2 at http://teamtreehouse.com/library/adding-info-windows
My code
google.maps.event.addListener(marker,'click',function(){});
Seems right but doesn't pass
3 Answers
Andrew Chalkley
Treehouse Guest TeacherCan you share your full code so we can see the context on where this line is?
Stefan Lyew
8,448 PointsHere it is:
Thanks,
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 = new google.maps.InfoWindow({content:"Magic Kingdom"});
google.maps.event.addListener(marker,'click',function(){});
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;
}
}
)
Andrew Chalkley
Treehouse Guest TeacherAhh I see...you have a scoping issue.
You are doing this line google.maps.event.addListener(marker,'click',function(){}); before var marker is defined. If you do it within the if block and after your create the new marker that should be fine.
Context is key :)
Regards Andrew
Joshua Johnson
6,364 PointsI seem to be having a similar issue but mine is in the if block.
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(){})
}
}
)
Joshua Johnson
6,364 Pointssorry that came across kinda blotchy.
Andrew Chalkley
Treehouse Guest TeacherHi Joshua
I've re-edited it with correct formatting...
The event listener task a string in the second argument so instead of click it's "click". What you've got in your code means that the second argument is an undefined value.
Regards, Andrew