0

Im working on App using React Native using user location, what i wanna do is while app is closed to check if user is at a location that already exists in the database and if he is Show a notification saying “ are you at John Doe place “

So to get started i need to know what’s needed to check user location in the background, and then compare the user location in the database and get the results if he is at some location that exists in the database show notifications

Any place where i should start ?

Sandy Smarue
  • 71
  • 1
  • 7

2 Answers2

1

You will probably have to have:

  • Previously requested the appropriate rights to the user (location, notifications,..)
  • A background task running periodically or a watcher on the user's position
  • A way to access the user's location (see navigator.geolocation.getCurrentPosition(...) or navigator.geolocation.watchPosition(...))

You can combine that with network calls and notifications and you should be able to get to the desired behavior.

This example may help you getting started.

vbuzze
  • 930
  • 1
  • 11
  • 25
  • at what point should i check if the place/position is exists in the database and how do i do that without affecting user network overload – Sandy Smarue Aug 04 '19 at 02:14
0

You can use the Geolocation API to get user location, if they permit the app to know their location. I'd add it to a snippet here but stackoverflow has disabled use of the Geolocation API.

const successCallback = positionObj => console.log(positionObj);
const errorCallback = positionError => console.error(positionError);

navigator.geolocation.getCurrentPosition(successCallback, errorCallback);

Working JSFiddle here.

GenericUser
  • 3,003
  • 1
  • 11
  • 17
  • at what point should i check if the place/position is exists in the database and how do i do that without affecting user network overload – Sandy Smarue Aug 04 '19 at 02:15
  • 1
    I would start with the critical pieces of answering "how frequently should we check users locations at a minimum" and go from there. Everything else is honestly going to be dependent on your architecture. There's going to be a different answer if it's something that can easily scale, like an AWS environment, or if it's something that needs more direct management. This will also be dependent on the size of the userbase. – GenericUser Aug 04 '19 at 03:01
  • 1
    If you are checking their location on major events (logins/page loads, route changes, etc), then it should be a more manageable situation. But if you are expecting to frequently poll your active users to see if their location has changed then you could have a problem. What I provided in this answer is what can be done on the client side to provide the necessary information. The health of your application and servers is going to be very subjective to your current situation and needs. – GenericUser Aug 04 '19 at 03:05
  • thank you this is really helpful, i was hoping to active something like [Swarm App]( https://en.wikipedia.org/wiki/Swarm_(app) ) it send you notification whenever you are at place known on the map to check in. – Sandy Smarue Aug 04 '19 at 10:33