Initialize React Google Maps StandaloneSearchBox with geocode

后端 未结 2 375
日久生厌
日久生厌 2021-01-15 21:31

Can someone tell me how to initialize React Google Maps\'s StandaloneSearchBox component with types: [\'geocode\'] (like in the original google.maps.places.Autocomplete, so

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-15 22:13

    StandaloneSearchBox is a wrapper around google.maps.places.SearchBox.
    So Google documentation for SearchBox says that:

    The SearchBox constructor takes two arguments:

    • An HTML input element of type text. This is the input field that the SearchBox service will monitor and attach its results to.
    • 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: https://developers.google.com/maps/documentation/javascript/places-autocomplete#places_searchbox

    So you can call this component like this:

    Where defaultBounds is a LatLngBounds class which is represents a rectangle in geographical coordinates.

提交回复
热议问题