When attempting to access the current location using the build browser navigator function, an error is thrown stating that navigator is undefined. To resolve this issue, the following code was added: if (typeof navigator !== 'undefined'). However, after implementing this fix, the application now throws an error stating that routeConfiguration is not a function
Steps to reproduce the behaviour:
Create a new file called useCurrentLocation.js with this code
import { types as sdkTypes } from '../util/sdkLoader';
const { LatLng } = sdkTypes;
export const useCurrentLocation = async () => {
if (typeof navigator !== 'undefined') {
if (!('geolocation' in navigator)) {
throw new Error('Geolocation not available in the browser');
}
**Expected behavior** This should run without error when `npm run dev-server`
**Screenshots**
![image](https://github.com/sharetribe/ftw-daily/assets/71048565/a60d59f3-e7d2-4a78-821f-3e0c54a9591e)
When attempting to access the current location using the build browser navigator function, an error is thrown stating that navigator is undefined. To resolve this issue, the following code was added:
if (typeof navigator !== 'undefined')
. However, after implementing this fix, the application now throws an error stating that routeConfiguration is not a functionSteps to reproduce the behaviour:
export const useCurrentLocation = async () => { if (typeof navigator !== 'undefined') { if (!('geolocation' in navigator)) { throw new Error('Geolocation not available in the browser'); }
} else { return; } };
const { useCurrentLocation } = await import('../../hooks/useCurrentLocation'); const getCurrentLocation = useCurrentLocation(); async function fetchResults() { const latlng = await getCurrentLocation; console.log(latlng); const results = { address: '', origin: latlng, bounds: locationBounds( latlng == 'User denied Geolocation' ? null : latlng, config.maps.search.currentLocationBoundsDistance ), }; return results; }