U
user1661142
Guest
I'm struggling with this extremely weird error. I have this piece of code:
<script>
var mapOptions = {zoom : 16};
var map;
var address;
var marker;
var geocoder;
$("#map-canvas").css({
width : String($(window).width()) + "px",
height : String($(window).height()) + "px"
});
rbf_selectQuery("SELECT name, streetAddr1, city, country FROM flag",999, //AJAX
function(values)
{
geocoder = new google.maps.Geocoder();
map = new google.maps.Map(document.getElementById("map-canvas"),mapOptions);
for (var k = 0; k < values.length; ++k)
{
address = values[k][1] + " " + values[k][2];
geocoder.geocode({'address':address},
function(results,status)
{
console.log(k);
if (status != google.maps.GeocoderStatus.OK )
{
console.log("Error " + status);
return;
}
if(k==0)
{
map.setCenter(results[0].geometry.location);
map.setZoom(16);
}
marker = new google.maps.Marker({
map : map,
position : results[0].geometry.location,
title : values[k][0],
visible : true
});
});
}
});
</script>
What I'm trying to do is draw all markers from the addresses that I received from the query unto the map. I know that the query is returning the correct data into the 2-d array. Now the error I'm getting is this:
Uncaught TypeError: Cannot read property '0' of undefined
Somehow (and this is when it gets weird), the statement "console.log(k)" outputs "2", now, to me this is impossible because I know for a fact that the "values.length" is 2, I have a console.log on my side that tests it and I know for a fact the length is 2. What might also be of importance is the fact that there is literally only that one line of output.
Any thoughts?
Continue reading...
<script>
var mapOptions = {zoom : 16};
var map;
var address;
var marker;
var geocoder;
$("#map-canvas").css({
width : String($(window).width()) + "px",
height : String($(window).height()) + "px"
});
rbf_selectQuery("SELECT name, streetAddr1, city, country FROM flag",999, //AJAX
function(values)
{
geocoder = new google.maps.Geocoder();
map = new google.maps.Map(document.getElementById("map-canvas"),mapOptions);
for (var k = 0; k < values.length; ++k)
{
address = values[k][1] + " " + values[k][2];
geocoder.geocode({'address':address},
function(results,status)
{
console.log(k);
if (status != google.maps.GeocoderStatus.OK )
{
console.log("Error " + status);
return;
}
if(k==0)
{
map.setCenter(results[0].geometry.location);
map.setZoom(16);
}
marker = new google.maps.Marker({
map : map,
position : results[0].geometry.location,
title : values[k][0],
visible : true
});
});
}
});
</script>
What I'm trying to do is draw all markers from the addresses that I received from the query unto the map. I know that the query is returning the correct data into the 2-d array. Now the error I'm getting is this:
Uncaught TypeError: Cannot read property '0' of undefined
Somehow (and this is when it gets weird), the statement "console.log(k)" outputs "2", now, to me this is impossible because I know for a fact that the "values.length" is 2, I have a console.log on my side that tests it and I know for a fact the length is 2. What might also be of importance is the fact that there is literally only that one line of output.
Any thoughts?
Continue reading...