I've been beating my head at this for a while, so I've finally broken down and decided to ask for input.
I have to construct an object that uses an array of coordinates to outline a map. I've created an Array of Arrays (at least I thought) so I can iterate through the length and create however many objects needed. The problem is, the values in my Array are strings - they're not actually referencing the arrays. The object then gets mad and says it's an invalid parameter.
I tried using split(), but it seems to have had no effect. I've manually input path:boundaries0, and that seems to work just fine. I've been looking at this so long I think I've lost brain cells. If anyone can even just set me on the right path, that'd be awesome.
var arrays = 50; //Set this to how many arrays are created.
var boundariesAr = new Array;
var boundaries = new Array;
for(i=0;i<arrays;){
boundariesAr.push('boundaries' + i);
i++;
};
for(j=0;j<boundariesAr.length;){
var serviceArea = "serviceArea" + j;
var currentArray = boundariesAr[j];
var currentItem = currentArray.split(" ");
serviceArea = new google.maps.Polygon({
path:currentItem,
geodesic:true,
strokeColor:'#000',
strokeOpacity:1.0,
strokeWeight:2,
fillColor: '#FF0000',
fillOpacity: 0.35
});
serviceArea.setMap(map);
j++;
};
EDIT - updated code (only a snippet) This is a truncated look at what the arrays look like:
var boundaries0 = [
new google.maps.LatLng(65.307997,-146.130689),
new google.maps.LatLng(65.291840,-146.198712),
];
var boundaries1 = [
new google.maps.LatLng(64.703884,-147.150958),
new google.maps.LatLng(64.703189,-147.155442),
];
var arrays = 50; //boundaries0[],boundaries1[], etc
var boundariesAr = new Array;
for(var i=0;i<arrays;i++){
boundariesAr.push(boundaries);
};
for(var j=0;j<boundariesAr.length;j++){
var serviceArea = "serviceArea" + j;
var currentArray = boundariesAr[j];
var currentItem = currentArray.split(" ");
serviceArea = new google.maps.Polygon({
path:currentItem,
geodesic:true,
strokeColor:'#000',
strokeOpacity:1.0,
strokeWeight:2,
fillColor: '#FF0000',
fillOpacity: 0.35
});
serviceArea.setMap(map);
};
Thank you to some fantastic people who took time out of their day to help. I'd buy you drinks if I could.
This finally worked - (and I feel silly for not nesting the arrays to begin with)
var boundaries = [];
boundaries[0] = [
new google.maps.LatLng(65.307997,-146.130689),
new google.maps.LatLng(65.291840,-146.198712),
];
boundaries[1] = [
new google.maps.LatLng(64.703884,-147.150958),
new google.maps.LatLng(64.703189,-147.155442),
];
var arrays = 50; //Set this to how many arrays are created.
for(var j=0;j<arrays;j++){
serviceArea = new google.maps.Polygon({
path:boundaries[j],
geodesic:true,
strokeColor:'#000',
strokeOpacity:1.0,
strokeWeight:2,
fillColor: '#FF0000',
fillOpacity: 0.35
});
serviceArea.setMap(map);
};
'boundaries' + i(what you pushed toboundariesAr) is a string. What did you expect?for (var i=0; i<arrays; i++)!