【问题标题】:Restricting autocomplete search to particular region (google places)将自动完成搜索限制在特定区域(谷歌地方)
【发布时间】:2018-08-12 03:15:16
【问题描述】:

我想限制我只搜索我所在城市内的地方,非常感谢任何帮助

我正在使用 => FaridSafi/react-native-google-places-autocomplete

谢谢

【问题讨论】:

标签: react-native google-places-api googleplacesautocomplete


【解决方案1】:

在你的代码中添加这个

query={{
                    // available options: https://developers.google.com/places/web-service/autocomplete
                    key: "API KEY",
                    language: "en", // language of the results
                    location: "-33.865143, 151.209900",
                    radius: "100000", //100 km
                    components: "country:au", // country name
                    strictbounds: true,
                  }}

【讨论】:

    【解决方案2】:
         <GooglePlacesAutocomplete
          ref={ref}
          currentLocation={true}
          placeholder="Enter Location"
          minLength={2}
          autoFocus={false}
          returnKeyType={'default'}
          placeholderTextColor="black"
          fetchDetails={true}
          enablePoweredByContainer={false}
          query={{
            key: 'Your API key',
            language: 'en',
            types: '(cities)', <=== use this to only show country cities
            components: 'country:pk', , <=== use this to restrict to country
          }}
        
          filterReverseGeocodingByTypes={[
            'locality',
            'administrative_area_level_1',
          ]}
          GooglePlacesSearchQuery={{
            rankby: 'distance',
          }}
          nearbyPlacesAPI="GooglePlacesSearch"
          styles={{
            textInputContainer: styles.textInputContainer,
            description: {
              fontWeight: 'bold',
            },
            textInput: styles.textInputAutoPlace,
          }}
        />
    

    【讨论】:

      猜你喜欢
      • 2012-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-25
      • 2019-08-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多