IE Google computeDistanceBetween返回NaN

时间:2014-08-05 18:29:52

标签: javascript google-maps internet-explorer

我已经阅读过有关发送字符串而不是数字的帖子enter link description here,但我在发送之前专门调用了parseFloat()。这只发生在IE中。

var getLatLngExtraAddr = function(tempAddr, y){
if(mIE == "true"){                  
    $.ajax({
            url: "php/ie_extra.php",
            data: {"address": tempAddr},
            dataType: "text",
            success: function(data){
                var msg = $.parseJSON(data);
                //console.log("msg "+msg);
                extraAddrLat.push(parseFloat(msg.results[0].geometry.location.lat));
                extraAddrLng.push(parseFloat(msg.results[0].geometry.location.lng));
                var p1 = new google.maps.LatLng(parseFloat(origLat[0]), parseFloat(origLng[0]));
                var p2 = new google.maps.LatLng(parseFloat(extraAddrLat[y]), parseFloat(extraAddrLng[y]));
                console.log("extraAddrLat["+y+"] "+extraAddrLat[y]);
                mAddressesObj[y].dist = (google.maps.geometry.spherical.computeDistanceBetween(p1, p2) * 0.000621371192).toFixed(2);
                console.log("mAddressesObj[y].dist "+mAddressesObj[y].dist);
            }
    });
}else{
    $.ajax({
            url: "https://maps.googleapis.com/maps/api/geocode/json",
            data: {"address": tempAddr},
            success: function(data){
                if(typeof(data.results[0]) != "undefined"){
                    extraAddrLat.push(parseFloat(data.results[0].geometry.location.lat));
                    extraAddrLng.push(parseFloat(data.results[0].geometry.location.lng));
                    var p1 = new google.maps.LatLng(parseFloat(origLat[0]), parseFloat(origLng[0]));
                    var p2 = new google.maps.LatLng(parseFloat(extraAddrLat[y]), parseFloat(extraAddrLng[y]));
                    mAddressesObj[y].dist = calcDistance(p1, p2);
                    console.log("mAddressesObj[y].dist "+mAddressesObj[y].dist);
                }
            }
    }); 
 }
}

在修复了“拒绝访问错误”和其他多个错误之后,我创建了一个代理,允许IE读取来自curl的geometry.location.lat。

以下是来自IE的控制台日志:

LOG: extraAddrLat[2] undefined 
LOG: mAddressesObj[y].dist NaN 
LOG: extraAddrLat[0] 53.5408345 
LOG: mAddressesObj[y].dist NaN 
LOG: extraAddrLat[3] undefined 
LOG: mAddressesObj[y].dist NaN 
LOG: extraAddrLat[1] 53.52903209999999 
LOG: mAddressesObj[y].dist NaN 
LOG: extraAddrLat[5] undefined 
LOG: mAddressesObj[y].dist NaN 
LOG: extraAddrLat[4] 53.54180909999999 
LOG: mAddressesObj[y].dist NaN 
LOG: extraAddrLat[6] 53.5441529 
LOG: mAddressesObj[y].dist NaN 

正如您所看到的,我收到了每个地址的正确lat,lng,但是当我尝试将这些值发送到google.maps.geometry.spherical.computeDistanceBetween时 - 它返回NaN

我正在将它发送到另一个函数(calcDistance),就像我对所有其他浏览器一样,但我想也许是因为IE本身将它转换为字符串而丢失了parseFloat。结果,我直接设置了对象mAddressObj的属性“dist”,仍然是“NaN”

如何?更重要的问题,为什么IE?

像往常一样,提前谢谢

0 个答案:

没有答案