Home > Net >  Google Places Autocomplete/SearchBox with bounds and text search
Google Places Autocomplete/SearchBox with bounds and text search

Time:04-22

When I'm searching within the SearchBox component https://developers.google.com/maps/documentation/javascript/examples/places-searchbox

the official demo example (link above) doesn't work for me.

  1. The map shows Sydney
  2. I type in "mcdonalds" as an example
  3. I select the first suggestion from the list (McDonald's) https://take.ms/cs03e
  4. the map gets repositioned to my country (~ a lightyear away from Sydney) and displays the results only around my physical location.

The documentation about bounds

An options argument, which can contain the bounds property: bounds is a google.maps.LatLngBounds object specifying the area in which to search for places. The results are biased towards, but not restricted to, places contained within these bounds.

I tried bounds, location radius, componentRestrictions to country, but none gave the expected pehavior.

I understand that the bounds are not always respected, although the way it works at my end is not usable at all.

We noticed the same malfunctioning within an existing app of ours that uses SearchBox which was working perfectly in the past. Bounds were respected.

Can anyone suggest a workaround or explanation for this behavior?

I tried alternatives such as

  • nearbySearch => respects bounds, but no option to define free text search
  • freetextSearch => only freetext search, no bounds
  • AutocompleteService.getPlacePredictions => respects bounds and freetext search but returns only ids of places and not locations (needs additional query for location to render markers)
  • PlacesService.findPlaceFromQuery => only returns one item

The goal is to search (freetext) for establishments and addresses within bounds and display them on the map as markers.

UPDATE: Please see the inconsistent behavior from different IPs: https://take.ms/CQUDJ testing from most countries the bias is not working as it should.

Thanks

CodePudding user response:

The issue is confirmed by Google, please see the related tickets.

https://issuetracker.google.com/issues/229752141 (mine) https://issuetracker.google.com/issues/228928701

  • Related