Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Pincode based search for exact distance between donors and requestor. #47

Open
JPRMohnish opened this issue May 3, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@JPRMohnish
Copy link

What if users want to search donors in nearby area based upon their pincode?.
We built the same type of API in node js and here it is the link of the website. PlasmaDonor

Solution how to map pincode to distance between donor and requestor.
Sadly we wrote the above apis and frontend both in js. thus I can't help much with the code but here is what we did.
At the time of registration take a valid pincode from the donor. here is the api to validate the pincode . This api also gives the latitude and longitude coordinates of the place asked and nearby places.

The next step is to store this latitude and longitude for each user. and then at the time of someones request for donors through a pincode, again call the same api to get lat long of the current requestors pincode. now we have lat long of requestor and remember we had lat long of donors in our database. For the purpose to not traverse the whole database we only search those pincodes in database which are having first 3 digit same as the requestors pincode and to most extent it works fine.

suppose you have some list of donors now from your database which are near to current pincode. then run this function to get the exact distance between the donors and the requestor.

function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) {
    lat1 = parseFloat(lat1); lon1 = parseFloat(lon1);
    lat2 = parseFloat(lat2); lon2 = parseFloat(lon2);
    console.log(lat1, lon1, lat2, lon2);
    var R = 6371; // Radius of the earth in km
    var dLat = deg2rad(lat2 - lat1);  // deg2rad below
    var dLon = deg2rad(lon2 - lon1);
    var a =
        Math.sin(dLat / 2) * Math.sin(dLat / 2) +
        Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
        Math.sin(dLon / 2) * Math.sin(dLon / 2)
        ;
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    var d = R * c; // Distance in km
    return d;
}

Now you have distance of a requestor with respect to all donors apply some more filters regarding blood group age and gender matching and shoo the results. for more details here is our backend in nodejs link. I really wanted to contribute but lack of php skills.
For more info on how we did it.
Our nodejs backend repo link.

https://github.com/JPRMohnish/PlasmaBackend/

We wanted users to get involved in our website and populate the database but since this is much popular website and having a greater user database. I want that you continue this project . Thank you And help India fight Covid 19.

For more info ping me on linkedin.

@JPRMohnish JPRMohnish added the enhancement New feature or request label May 3, 2021
@JPRMohnish JPRMohnish changed the title Feature: [title]Pincode based search for exact distance between donors and requestor. Feature: [Pincode based search for exact distance between donors and requestor.] May 3, 2021
@JPRMohnish JPRMohnish changed the title Feature: [Pincode based search for exact distance between donors and requestor.] Feature: Pincode based search for exact distance between donors and requestor. May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants