-1

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?

0

1 Answer 1

1

The class is LatLng, not latLng. Javascript's case-sensitive; it should be

list.push(new google.maps.LatLng(tempLong,tempLat));

... not

list.push(new google.maps.latLng(tempLat, tempLong));

Also you do new google.maps.latLng(tempLong,tempLat) from which I inferred you've got your latitude and longitude mixed up.

See: https://developers.google.com/maps/documentation/javascript/reference#LatLng

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.