计算标记之间的距离

时间:2013-11-20 06:02:27

标签: javascript google-app-engine google-maps google-maps-markers

我有一个嵌套循环,我试图计算一个标记与另一个标记的距离,不包括它自己。我正在使用google.maps.geometry.spherical.computeDistanceBetween(p1, p2)来计算距离,但是我得到了一个错误,我似乎无法解决这个问题。

代码

function calculateDistance(p1, p2){
    return (google.maps.geometry.spherical.computeDistanceBetween(p1, p2) / 1000).toFixed(6);
}

for(var p = 0 ; p < global_citizens.length; p++){

    //console.log(global_citizens[p].socialSecurityNumber);
    pt1 = new google.maps.LatLng(marker[p].getPosition().lat(),marker[p].getPosition().lng());

    for(var k= 0; k < global_citizens.length; k++){
        if(global_citizens[p].socialSecurityNumber != global_citizens[k].socialSecurityNumber){
            console.log('Comparing ' + global_citizens[p].socialSecurityNumber + ' and ' + global_citizens[k].socialSecurityNumber);

            pt2 = new new google.maps.LatLng(marker[k].getPosition().lat(),marker[k].getPosition().lng());

            var kmApart = calculateDistance(pt1,pt2);

            if(kmApart <= 0.030480 ){
                console.log(global_citizens[p].socialSecurityNumber + 'is less then 100 feet from '+ global_citizens[k].socialSecurityNumber);
            }
        }
    }
}

错误

TypeError: ({ob:10.4915892, pb:-61.40605900000003}) is not a constructor    

...ew new google.maps.LatLng(marker[k].getPosition().lat(),marker[k].getPosition()....

1 个答案:

答案 0 :(得分:1)

查看代码:

pt2 = new new 

删除new