0

I am doing the extra features and trying to plant two gas stations to google maps. For this I created another js file defining var GASSTATION with the two individual gas stations and their lat and lng. I then added the following code to service.js in populate() after the code, in which maps is populated with houses. However as I run the program, it does not load properly and earth and maps do not show up in the browser. Can anyone identify what is wrong with this snippet of code?

for(var station in GASSTATION){ new google.maps.Marker({ icon: "http://mapicons.nicolasmollet.com/wp-content/uploads/mapicons/shape-default/color-9d7050/shapecolor-color/shadow-1/border-dark/symbolstyle-white/symbolshadowstyle-dark/gradient-no/e-bike-charging.png", map: map, position: new google.maps.LatLng(GASSTATION[station].lat, GASSTATION[station].lng), title: Gas Station
}); }

3
  • You might want to try and indent your code with 4 spaces so that it turns into an actual codeblock. Now it's just one big unreadable paragraph.
    – ZeroStatic
    Sep 9, 2014 at 11:40
  • Ok true, in my code it is actually an actual code block, but the formatting on stack exchange has messed it up. sorry
    – Kevin Wu
    Sep 9, 2014 at 11:52
  • You can click edit underneath your question and fix it so it becomes readable. (Imo one of the easier ways to do this is to use a text editor and put your block in there and tab 2 times, then copy that back over here.)
    – ZeroStatic
    Sep 9, 2014 at 11:56

1 Answer 1

1

Things 'wrong' with the snippet:

Not necessarily wrong but could be done differently

for(var x in array) { }

Lots of people consider iterating over a javascript array like this a bad idea. See: https://stackoverflow.com/questions/500504/why-is-using-for-in-with-array-iteration-such-a-bad-idea

An alternative is:

for(var i=0,j=GASSTATION.length;i<j;i++) { //Access me with GASSTATION[i] }

Title attribute without quotes

This should really be wrong

Your marker has a title attribute, which contains what I presume is supposed to be the string: 'Gas Station' but in your snippet it does not have quotes surrounding the title.

title: Gas Station

should be

title: 'Gas Station'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .