Currently, I have a filter function that is designed to check the latitude and longitude distance of objects within an array against the range selected by the user. However, there is a problem in which some objects within the array do not possess latitude and longitude attributes at all. This issue causes the filter to malfunction. Is there a possible solution to skip over objects lacking latitudinal and longitudinal values or those with both latitudes and longitudes set to 0?
Here is the snippet of code:
function distanceFromFunc(distanceFrom) {
var m;
var n;
var positionContainer = [];
var docLat;
var docLon;
var rowIdFromObj;
var rowObj;
var rowsArray;
if (distanceFrom === "1") {
vm.selectedRadius = 1609.344 //1 mile
} else if (distanceFrom === "2") {
vm.selectedRadius = 3218.688 //2 miles
} else if (distanceFrom === "5") {
vm.selectedRadius = 8046.720 //5 miles
} else if (distanceFrom === "10") {
vm.selectedRadius = 16093.440 //10 miles
} else if (distanceFrom === "20") {
vm.selectedRadius = 32186.880 //20 miles
} else if (distanceFrom === "50") {
vm.selectedRadius = 80467.200 //50 miles
} else if (distanceFrom === "999999") {
vm.selectedRadius = 0
};
function filterByDist(value) {
console.log("VALUE IS ------>" + JSON.stringify(value));
var dist = distance(myLat, myLon, value.locations[0].Lat, value.locations[0].Long);
if (dist <= distanceFrom) {
console.log("the dist is: " + dist);
return value
};
};
var digestedArray = originalData2.filter(filterByDist)
$scope.locatorGridData = digestedArray;
};
The point where it seems to break occurs on this line:
var dist = distance(myLat, myLon, value.locations[0].Lat, value.locations[0].Long);