var markers3 = [];
for (var i = 0; i < 1964; i++) {
var dataPhoto = data8.weblandmarks8[i];
if(data8.weblandmarks8[i].ip2==data8.weblandmarks8[i+1].ip2 )
{
var k=i+2;
while(1)
{
if((data8.weblandmarks8[k].ip2) == (data8.weblandmarks8[i].ip2))
k++;
else break;
}
for (var j = i; j < k; j++)
{
var latLng = new google.maps.LatLng(data8.weblandmarks8[j].latitude,data8.weblandmarks8[j].longitude);
var marker = new google.maps.Marker({position: latLng,icon: webicon,title:data8.weblandmarks8[j].webaddress});
markers3.push(marker);
}
i=k-1;
}
}
google maps application
I get the following error in firefox
Error: data8.weblandmarks8[k] is undefined Source File: file:///Applications/MAMP/htdocs/geo/js/myscript.js Line: 140
I have defined K but why does firefox say that the json data accessed with it is undefined?
the same data can be accessed with i variable.
edit:
I have a json data file which I am accessing by
its working
but the error is with that specific line only
This calls for some basic debugging first: For what value of
kdoes it fail? What happens if you try to address that value directly?I’m fairly sure
k(beingi+2) simply reaches the end of the list at some point – as it stands, the code needs 1966 elements to be present in order to work.