react-native-geolocation
react-native-geolocation copied to clipboard
geloaction isnt giving proper lat and longs
trafficstars
with this code import Geolocation from '@react-native-community/geolocation';
/**
- Utility function to fetch the current location (latitude and longitude).
- @returns {Promise<{ latitude: number, longitude: number } | { error: string }>} - A promise that resolves to an object with latitude and longitude or an error message. */ export const getCurrentLocation = async () => { return new Promise((resolve, reject) => { Geolocation.getCurrentPosition( (position) => { const { latitude, longitude } = position.coords; resolve({ latitude, longitude }); }, (error) => { console.error('Error fetching location:', error); reject({ error: 'Unable to fetch location' }); }, { enableHighAccuracy: true, // Set to true for better accuracy timeout: 15000, maximumAge: 10000, }, ); }); };