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
Pedro Pinto
3,798 PointsAdding Point Markers to a Map: task 4/6
I don't know which is bet best manner to code this part of the exercise: "...create a "google.maps.Marker" in "theMap" and at the position of the first element in "results", like in the video and push it on to the "markers" array."
I have this code:
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"};
geocoder.geocode(geocoderOptions, function (results, status) {
if (status == google.maps.GeocoderStatus.OK)
});
Can someone give me some highlights about the proper manner to solve this task?
Thanks
4 Answers
Andrew Chalkley
Treehouse Guest TeacherHere's some comments to point you in the right direction ...
var geocoderOptions = {address:"Magic Kingdom, Disney World"};
geocoder.geocode(geocoderOptions, function (results, status) {
if (status == google.maps.GeocoderStatus.OK)
{ //Added to curly braces
// Create a variable called marker then set a new google.maps.Marker
// Use the push() method on markers to push the marker variable on to the array
}
});
Let me know how you get on.
var geocoderOptions = {address:"Magic Kingdom, Disney World"}; geocoder.geocode(geocoderOptions, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { var marker = new google.maps.Marker({map:theMap,position:results[0]}); markers.push(marker); } });
All I get is "null" for a message. Any other sort of hint with a little more meat?
Andrew Chalkley
Treehouse Guest TeacherSorry you're having issues Michael.
Generally a 'null' message appears when there's a syntax error or if something unexpected happens in our code challenge engine. Our dev team is looking in to making these hints a lot better.
I think your issue is w.r.t the results being passed in. It's results[0].geometry.location.
thank you.