0

我希望将 Google Places 搜索结果限制在我的用户当前位置周围 20 英里的范围内。

将半径参数添加到查询根本不起作用。这是我的代码:

          query={{
    // available options: https://developers.google.com/places/web-service/autocomplete
    key: 'AIzaSyCMFiyTGVGJQgi1AOShIuRppi9JqcSgobw',
    language: 'en', // language of the results
    types: ['street_address', 'establishment'], // default: 'geocode'
    components: 'country:us'
    latitude: 32.795969,
      longitude: -80.028863,
      radius: 100
  }}
  styles={locationAutocompleteStyle}

  currentLocation={false} // Will add a 'Current location' button at the top of the predefined places list
  currentLocationLabel="Current location"
  nearbyPlacesAPI="GooglePlacesSearch" // Which API to use: GoogleReverseGeocoding or GooglePlacesSearch
  GoogleReverseGeocodingQuery={{
    // available options for GoogleReverseGeocoding API : https://developers.google.com/maps/documentation/geocoding/intro
  }}
  GooglePlacesSearchQuery={{
    // available options for GooglePlacesSearch API : https://developers.google.com/places/web-service/search
    // rankby: 'distance',
  }}
4

1 回答 1

2

您提供的半径以米为单位,它应该是一个字符串

你可以试试这个

     <GooglePlacesAutocomplete
                            placeholder='search'
                            minLength={2}
                            autoFocus={true}
                            returnKeyType={'default'}
                            fetchDetails={true}
                            query={{
                                key: '***********8',
                                language: 'es', // language of the results
                                location: '20.8840744, -100.7607736',
                                radius: '15000', //15 km
                                components:'country:mx',
                                strictbounds: true,
                            }}
    />
于 2018-05-16T07:51:07.610 回答