Welcome to TypeScript Geolocation Utils! This lightweight utility helps you easily fetch a user's geolocation using the browser's native Geolocation API. With a simple, Promise-based design, itโs perfect for modern frontend applications.
- Lightweight: Minimal footprint for quick integration.
- Promise-based: Enjoy a clean and modern asynchronous approach.
- Browser Compatibility: Works seamlessly across all modern browsers.
- TypeScript Support: Fully typed for better development experience.
- Easy to Use: Simple API that anyone can understand.
To install TypeScript Geolocation Utils, you can use npm or yarn. Run the following command in your terminal:
npm install typescript-geolocation-utilsor
yarn add typescript-geolocation-utilsTo get started, simply import the utility in your TypeScript or JavaScript file:
import { getGeolocation } from 'typescript-geolocation-utils';
getGeolocation()
.then((location) => {
console.log('User Location:', location);
})
.catch((error) => {
console.error('Error fetching location:', error);
});This code will log the user's latitude, longitude, and accuracy to the console.
This function fetches the user's current geolocation. It returns a Promise that resolves to an object containing the following properties:
- latitude: The user's latitude.
- longitude: The user's longitude.
- accuracy: The accuracy of the location in meters.
const fetchLocation = async () => {
try {
const location = await getGeolocation();
console.log(`Latitude: ${location.latitude}, Longitude: ${location.longitude}`);
} catch (error) {
console.error('Failed to fetch location:', error);
}
};
fetchLocation();We welcome contributions! If you would like to contribute to this project, please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/YourFeature). - Make your changes and commit them (
git commit -m 'Add new feature'). - Push to the branch (
git push origin feature/YourFeature). - Open a Pull Request.
Your contributions help improve this utility for everyone.
This project is licensed under the MIT License. See the LICENSE file for details.
For the latest updates and releases, please visit our Releases section. Here, you can download the latest version and execute it in your projects.
Thank you for checking out TypeScript Geolocation Utils! We hope this utility makes it easier for you to work with geolocation in your applications. If you have any questions or suggestions, feel free to reach out or open an issue. Happy coding!
For more information on releases, visit Releases.