Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The function 'routeConfiguration' does not work. #1601

Open
deepakrh185 opened this issue Nov 28, 2023 · 0 comments
Open

The function 'routeConfiguration' does not work. #1601

deepakrh185 opened this issue Nov 28, 2023 · 0 comments

Comments

@deepakrh185
Copy link

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

image

Steps to reproduce the behaviour:

  1. 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');
    }

    const options = {
      enableHighAccuracy: true,
      timeout: 5000,
      maximumAge: 0,
    };

    try {
      const position = await new Promise((resolve, reject) => {
        navigator?.geolocation?.getCurrentPosition(resolve, reject, options);
      });

      return new LatLng(position.coords.latitude, position.coords.longitude);
    } catch (error) {
      console.log('error->>>Location', error);
      return error.message;
    }
  } else {
    return;
  }
};

2.Call the function in Searchpage.duck.js to access the current Location

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;
}

Expected behavior This should run without error when npm run dev-server

Screenshots
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant