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

use getGeocode before usePlacesAutocomplete #1105

Open
WJKwok opened this issue Dec 8, 2022 · 0 comments
Open

use getGeocode before usePlacesAutocomplete #1105

WJKwok opened this issue Dec 8, 2022 · 0 comments

Comments

@WJKwok
Copy link

WJKwok commented Dec 8, 2022

I want to use getGeocode to get latlng to input as requestOptions within usePlaceAutocomplete

something like that:

const CityPage = () => {
	const router = useRouter();
	const { cityName } = router.query;
	const [location, setLocation] = useState<LatLng>();

	getGeocode({ address: cityName }).then((results) => {
		const result = getLatLng(results[0]);
		setLocation(result)
	});

	const {
		ready,
		value,
		suggestions: { status, data },
		setValue,
		clearSuggestions,
	} = usePlacesAutocomplete({
		requestOptions: {
			location
			/* Define search scope here */
		},
		callbackName: 'initMap',
		debounce: 300,
	});

However, next.js complains about ReferenceError: window is not defined. I understand that google has not been initialised.. and the issue would be fixed if useGeocode is used after usePlacesAutocomplete.. but i need it this way and don't know how to go about it. Any advice?

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