IE Google computeDistanceBetween returns NaN

2019-09-02 20:45发布

I have read this post enter link description here concerning sending a string instead of number, but I am specifically calling parseFloat() before sending. This is only occuring in 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);
                }
            }
    }); 
 }
}

After fixing "access denied errors" and multiple other errors, I created a proxy to allow IE to read the geometry.location.lat coming from a curl.

Here is the console log from 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 

As you can see, I am receiving the correct lat, lng for each address, but then when I try to send those values to google.maps.geometry.spherical.computeDistanceBetween - it returns with NaN

I was sending it to another function (calcDistance), as I do with all other browsers, but I thought maybe the parseFloat was being lost somehow by IE itself converting it to a string. As a result, I set the property "dist" of the object mAddressObj directly and still "NaN"

How? And the more important question, why IE?

As usual, thanks in advance

0条回答
登录 后发表回答