0

I'm trying to populate data for markers on map. I can get it to work using static content but I would like to set sites content by reading from an array.

var sites = [
 ['User 1', 45.4210328, -75.6900218, 4],
 ['User 2', 40.315939, -105.440630, 2],
 ['User 3', 43.785890, -101.90175, 1],
 ['User 4', 39.99948, -105.28370, 3]
]; 
setMarkers(map, sites);

I tried this

for (var i = 0, len = arr.length; i < len; i++)
{
 var sites = [
 [arr[i].username, arr[i].latitude, arr[i].longitude, i
 ];
}

but as a result sites only contain one array i.e. the last array. Not all the arrays. How can I create multi-dimensional array within sites?

YakovL
8,45813 gold badges74 silver badges117 bronze badges
asked Jun 16, 2016 at 2:43
1
  • as a side note: your code now contains a syntax error (extra [ or missing ]) Commented Jun 16, 2016 at 2:58

1 Answer 1

1

Try this:

var sites = [];
for (var i = 0, len = arr.length; i < len; i++)
{ 
 sites.push([arr[i].username, arr[i].latitude, arr[i].longitude, i]);
}
answered Jun 16, 2016 at 2:48
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.