I want to create a system where user can login only if the user is in a radius of the given location.
I am using node.js, express.js, MongoDB.
Can someone please guide me what packages/Services should I use and how do I approach this problem
You have to make a boundary with geojson of your coverage area. To know your user location first of all get the user's current location with the device they use. store it in MongoDB. After getting the latitude or longitude of the user, use polygon-lookup npm package to identify the user is within your polygon radius or not.
If the user is in the location or not you can create a function like below -
let geoJsonMapData =
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
90.48509359359743,
23.823275544984423
],
[
90.33422470092773,
24.011030495565834
],
[
90.32435417175293,
23.77529123645138
],
[
90.50283908843996,
23.580546882813223
],
[
90.50519943237305,
23.592031281422017
],
[
90.47208085656167,
23.80909744710711
],
[
90.48509359359743,
23.823275544984423
]
]
]
}
}
]
};
const check_in_radius_or_not = (longitude, latitude) =>{
var lookup = new PolygonLookup( geoJsonMapData );
var poly = lookup.search( longitude, latitude );
if(poly){
return 1;
}else{
return 0;
}
}
If the function returns 1 they will be within the radius and able to log in, else if return 0 they are not within the given boundary and not able to log in.