Current Region Reports Screen
User can view the reports reported in his/her area. Firstly the user's current location is fetched via expo-location, then all reports are fetched and a filter is applied which filters out the reports whose location with respect to user's location is more than 100 KM(distance can be changed).
This function calculates the distance between two locations based on their latitude and longitude.
This fixes #269
Current Region Reports Screen
User can view the reports reported in his/her area. Firstly the user's current location is fetched via expo-location, then all reports are fetched and a filter is applied which filters out the reports whose location with respect to user's location is more than 100 KM(distance can be changed).
This function calculates the distance between two locations based on their latitude and longitude.
function calcCrow(lat1, lon1, lat2, lon2) {
var R = 6371; // km
var dLat = toRad(lat2 - lat1);
var dLon = toRad(lon2 - lon1);
var lat1 = toRad(lat1);
var lat2 = toRad(lat2);
var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
var d = R * c;
return d;
}
This function filters the reports
if (calcCrow(userLatitude, userLongitude, doc.data().latitude, doc.data().longitude) <= 100)
reports.push(doc.data())
})