Continuous location tracking for Node.js Telegram bot

Hey everyone! I’m working on a cool project - a Telegram bot using Node.js. The bot’s main job is to track user routes and give them stats like top speed, average speed, and trip duration. Maybe even show the route on a map later!

Here’s the thing: I need to get the user’s location in real-time. I tried doing this in the React part (Telegram mini apps), but it stops working when the app is minimized or running in the background.

Does anyone know how to keep tracking the location even when the user’s device is locked or the app isn’t active? I’m stumped and could really use some advice on this. Thanks in advance for any help!

I’ve tackled a similar challenge with location tracking in a Node.js project. The key is to leverage native mobile capabilities rather than relying solely on web technologies. For Android, consider implementing a foreground service with a persistent notification. This keeps your tracking active even when the app’s not in focus. On iOS, you’ll need to use background modes with Core Location, ensuring you have the right permissions set up.

On the server side, your Node.js bot can receive these updates via webhooks or periodic API calls. Store the location data in a database (MongoDB works well for geospatial data) and use it to calculate stats on demand. For real-time updates to Telegram, you might want to look into long polling or webhooks with the Telegram Bot API.

Remember, continuous tracking can be battery-intensive and privacy-sensitive. Implement smart tracking intervals and always be transparent with users about data collection. Good luck with your project!

hey mate, have u thought about using native mobile apps instead? like, build an android/ios app that can run in the background and keep sending location updates to ur node.js server. then ur bot can just grab that data and do its thing. might be a bit more work but it’ll prob solve ur problem. just remember to ask users if they’re cool with being tracked all the time lol