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

google maps- on click function to show markers

this is the last piece of code i wrote in my js file

function dropMarkers(catName){ for(var i = 0; i < 10; i++){ var myLatlng = new google.maps.LatLng(-43.540433 +i, 172.593575); var marker = new google.maps.Marker({ position: myLatlng, title:"Hello World!" });

// To add the marker to the map, call setMap(); marker.setMap(map); }

}

i would like to be able to when i click a certain button for all my data to show using markers from on click.

Very confused and would really appreciate some good guidance and step by step

Steven Parker
Steven Parker
242,191 Points

Is this for a course? A link to the course page might be helpful.

4 Answers

sure is! so i need to be able to show multiple markers using a for loop and a button

here is what i have

function dropMarkers(catName){ for(var i = 0; i < 10; i++){ var myLatlng = new google.maps.LatLng(-43.540433 +i, 172.593575); var marker = new google.maps.Marker({ position: myLatlng, title:"Hello World!"

});

    $.getJSON('json.restaurants.json', function(data)
              var locations = data.locations
    for (var i==locations=length){
        var location= locations[i];
        var latLng= (location lng, location.lat)

    }



    )
Steven Parker
Steven Parker
242,191 Points

Can you provide a link (the URL) to the course page?

it's all on brackets text editor so i can just do snippets and explain

Steven Parker
Steven Parker
242,191 Points

I understand that your code is in a local editor, but if you're working on a Treehouse course could you please provide a link to course page you are working with?

this isn't wholey from a treehouse course. the tutor is very confusing in the way he teaches which is why i came here to learn but i just would like to know what i am missing for this code

Steven Parker
Steven Parker
242,191 Points

I was hoping to refer to the course to help understand the assignment better. There would be examples in the videos and links in the teacher's notes. Several things in the code don't make sense to me, like:

  • for (var i==locations=length){ :point_left: this looks like a syntax error, but i'm not sure what was intended
  • var latLng= (location lng, location.lat) :point_left: same here, what's the intention?
  • a comment says "To add the marker to the map, call setMap();", but I don't see that happening

So if this is partly from a Treehouse course, can you provide a link to that?