javascript geofencing with embedded privacy

So I am utilizing the below code in javascript for a ionic / angular framework, and I want to embed https://cs.uwaterloo.ca/~uhengart/publications/pet07.pdf in a pratctical manner. I am attempting to figure how to add privacy with this geofencing.

 insideSquare(lat, lon, flat, flon, axis) {
        let original = axis;
        axis = (axis / 111.32) * 0.001; 

        if (lat > (flat - axis) &&
            lat < (flat + axis) &&
            lon > (flon - axis) &&
            lon < (flon + axis)) { console.log('location within :'+original+' meters');return true }
            else {return false}
    }
 distance = (latlngA, latlngB, isMiles) => {
    const toRadian = angle => (Math.PI / 180) * angle;
    const distance = (a, b) => (Math.PI / 180) * (a - b);
    const RADIUS_OF_EARTH_IN_KM = 6371;

    let lat1 = latlngA[0];
    let lat2 = latlngB[0];
    const lon1 = latlngA[1];
    const lon2 = latlngB[1];

    const dLat = distance(lat2, lat1);
    const dLon = distance(lon2, lon1);

    lat1 = toRadian(lat1);
    lat2 = toRadian(lat2);

    // Haversine Formula
    const a =
        Math.pow(Math.sin(dLat / 2), 2) +
        Math.pow(Math.sin(dLon / 2), 2) * Math.cos(lat1) * Math.cos(lat2);
    const c = 2 * Math.asin(Math.sqrt(a));

    let finalDistance = RADIUS_OF_EARTH_IN_KM * c;

    if (isMiles) {
        finalDistance /= 1.60934;
    }

    return finalDistance;
};

checkInsideFence() {
    this.insideSquare(39.6581064, -104.90189850000002, 39.5999854, -104.90271100000001, 6500);
    this.myDistance = this.distance([39.6581064, -104.90189850000002], [39.5999854, -104.90271100000001], false);
}

How accurate could I get within meters with the Haversine formula with my code or is there a more accurate way to do this in javascript or nodejs serverside? I have spent hours reading and checking stack overflow and cannot come up with an accurate answer because it seems like it depends on what coordinates I am using. Is there not a one size fits all formula? I want to place users in a large geofence of like 30 miles, and then iterate through those users and then have those users check to see if other users are in their personal fence. I think it would be terrible to compare each user against every other user as they could be in a different city or state, etc.. and that would just waste resources and the users time. My App will need to show users to other users within 1000 meters, preferably 500 meters, though I do not know if that is feasible. Help would be appreciated. The App will run on android, ios and web. Thankyou