-1

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

zsitro
  • 1,812
  • 3
  • 24
  • 34
  • The `SearchBox` constructor takes two arguments: [...] 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. Source: [official documentation](https://developers.google.com/maps/documentation/javascript/places-autocomplete#places-searchbox). – MrUpsidown Apr 20 '22 at 12:38
  • And as for what other options you have, they are all listed too: https://developers.google.com/maps/documentation/javascript/places#place_searches – MrUpsidown Apr 20 '22 at 13:49
  • Thank you, I understand it's not a strict bias, however, the way the searchbox works when searching for eg "gas station" is unusable. Do you agree? I also listed the alternatives I tried and why I can't rely on them. – zsitro Apr 20 '22 at 17:02
  • It works the way it's described... It's a widget and it's not meant to be customizable. The PlacesService has the [PlaceSearchRequest](https://developers.google.com/maps/documentation/javascript/reference/places-service#PlaceSearchRequest). – MrUpsidown Apr 20 '22 at 18:52
  • Sorry, but I disagree, I've attached an example https://take.ms/CQUDJ . Please see the inconsistent behavior from different IPs: testing from most countries the bias is not working as it should. I can understand your reasoning because it might work as expected on your end. – zsitro Apr 21 '22 at 06:16
  • Ok maybe. I have never tested it that way. In any case, as I said, it's just a widget that is not meant to be customized. You are using a tool to change your location, but what does that tool do and what does the widget do? The widget functionality is not very well documented so we don't really know how it works behind the scene. Anyway, use the Places Service and you should be able to achieve what you want. You could combine `PlaceSearchRequest` with an Autocomplete field (with Google data, or your own). – MrUpsidown Apr 21 '22 at 13:17
  • Just FYI, there are no McDonald's in Armenia ;) – MrUpsidown Apr 21 '22 at 13:21
  • @MrUpsidown thanks for your insights. – zsitro Apr 21 '22 at 18:12

1 Answers1

1

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

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

zsitro
  • 1,812
  • 3
  • 24
  • 34