ErrorPro / react-google-autocomplete

React components for google places API.
MIT License
474 stars 113 forks source link

How to set bounds correctly #203

Closed alexanderjarl91 closed 1 year ago

alexanderjarl91 commented 1 year ago

Hey. I've been trying to add strict bounds to the usePlacesWidget in NextJS but I cannot seem to get it right. I've trying trying to pass in bounds as

var southWest = new google.maps.LatLng(southWestLat, southWestLng);
var northEast = new google.maps.LatLng(northEastLat, northEastLng);

const bounds = google.maps.LatLngBounds(southWest, northEast)

but I'm not able to use the google script as it has not loaded yet.

I surfed through closed issues and found someone using the bounds prop like this:

options: { strictBounds: true, bounds: { north: 64.168864, south: 64.017664, east: 64.101766, west: 64.106564, }, types: ['geocode', 'establishment'], componentRestrictions: { country: 'is' }, }, After typing the widget with ReactGoogleAutocompleteProps, I have confirmed that these bound parameters are in fact the latitudes in numbers. However when I set them, I get an error and my input field fills up with error signs.

Screenshot 2023-02-04 at 17 08 31

alexanderjarl91 commented 1 year ago

The issue was that I was using both the apiKey prop and importing the google script in my _app.tsx. Seems to be working fine.