location-sender
v1.0.2
Published
Send users curreunt location on the specific endpoint for spection interval
Downloads
4
Readme
Location Sender Location Sender is a simple and lightweight JavaScript package that periodically sends the user's current geographic location to a specified API endpoint at configurable time intervals. This package leverages the browser's Geolocation API to obtain accurate latitude and longitude data and provides methods to start and stop location tracking based on user preference.
Features: Easy Integration: Quickly integrate location tracking functionality into any web or Node.js application. Customizable Interval: Set a custom time interval for how often to send the location data to the server. Start/Stop Control: Provides simple methods to start and stop sending location data at any time. Error Handling: Gracefully handles errors from the Geolocation API. Lightweight: Minimal dependencies, using only axios for HTTP requests. Installation: To install the package, run:
bash Copy code npm install location-sender Usage: Here's an example of how to use the Location Sender package:
javascript Copy code const LocationSender = require('location-sender');
// Replace with your API endpoint and interval time in milliseconds const apiUrl = 'https://your-api-endpoint.com/location'; const interval = 5000; // Send every 5 seconds
const sender = new LocationSender(apiUrl, interval);
// Start sending location sender.start();
// Stop after 30 seconds (for demonstration purposes) setTimeout(() => { sender.stop(); }, 30000); Parameters: apiUrl: (String) The endpoint URL where the location data will be sent via a POST request. interval: (Number) The interval time in milliseconds for sending location updates (default: 60,000 milliseconds or 1 minute). Methods: start(): Starts tracking and sending the location to the specified API endpoint at the configured interval. stop(): Stops the location tracking and sending process. Examples: To create a location sender that sends data every 10 seconds:
javascript Copy code const sender = new LocationSender('https://your-api.com/location', 10000); sender.start(); To stop the sender after 1 minute:
javascript Copy code setTimeout(() => { sender.stop(); }, 60000); Browser Compatibility: This package relies on the browser's Geolocation API, which is supported in most modern web browsers. Make sure to handle cases where geolocation is not available or the user denies location access.
Security and Privacy: Always ask for user consent before accessing and transmitting location data. Ensure that the API endpoint uses HTTPS to protect user privacy and data integrity. Handle location data responsibly and in accordance with local regulations and best practices for user privacy. License: This package is licensed under the MIT License. See the LICENSE file for more details.
End of Description Feel free to customize this description to match the tone and branding of your package or project!