I am doing an ajax call to the server to get latitude and longitude data and pushing them to a list containing google.maps.latLng coordinates. I'm doing some calculations because the matrix containing the data comes from a sparse matrix(will of course be rewritten because it's ugly so far). I know that my tempLong and tempLat values are correct, but I keep getting [Uncaught TypeError: google.maps.latLng is not a function] when i perform the ajax call. I suspect that this has do with the asynchronous call that ajax performs, but I'm not sure. I looked at this post and decided to put all my code in the .done{} function, but that does not help.
Anyway, here is my code:
function getMultipleArrays(){
var div = document.getElementById("map2");
$.get('getJSONObject', function(data) {
}).done(function(data){
var minLat = data.minLat;
var minLong = data.minLong;
var m = data.m;
var n = data.n;
var val = data.val;
var col = data.col;
var row = data.row;
var list =[];
var minLatCoo= minLat*1000000;
var minLongCoo= minLong*1000000;
var i, j, k,zeroIndex;
for(i=0; i<m;i++){
zeroIndex=0;
for(k=row[i]; k<row[i+1];k++){
j= col[k];
while(zeroIndex<j){
zeroIndex++;
}
minLatCoo= minLat*1000000;
minLongCoo= minLong*1000000;
for(var l=val[k]; l>0;l--){
minLatCoo+=zeroIndex;
var tempLat = minLatCoo/1000000;
minLongCoo+=i;
var tempLong = minLongCoo/1000000;
list.push(new google.maps.latLng(tempLong,tempLat));
console.log(tempLong + " - " + tempLat);
}
zeroIndex++;
}
}
console.log(list.length);
console.log("DONE!");
return list;
});}
The error occurs on the list.push(new google.maps.latLng(tempLong,tempLat)); line. Any ideas why it fails?