【问题标题】:react-native-google-places-autocomplete not workingreact-native-google-places-autocomplete 不工作
【发布时间】:2020-01-28 11:03:15
【问题描述】:

react-native-google-places-autocomplete 不起作用,我面临多个问题 1.places drop down 没有出现 2. onPress 处理程序根本没有被触发

注意:所有 google location api 都已启用,google maps api、places api 和 geocode api 都已启用,并提供了有效的 api 密钥。

我尝试了互联网上所有可能的解决方案 1. 设置 zIndex: 1000 一个高值以避免它被隐藏在其他视图后面 2.尝试创建新的RN App并仅添加此组件以保持项目清洁 3. 推荐其他SO post and tried to fix it

这里是代码 sn-p

<GooglePlacesAutocomplete
  placeholder="Search"
  minLength={2} // minimum length of text to search
  autoFocus={false}
  fetchDetails={true}
  onPress={(data, details = null) => {
    // 'details' is provided when fetchDetails = true
    console.log(data);
    console.log(details);
  }}
  getDefaultValue={() => {
    return ''; // text input default value
  }}
  query={{
    // available options: https://developers.google.com/places/web-service/autocomplete
    key: 'VALID_API_KEY',
    language: 'en', // language of the results
  }}
  styles={{
    description: {
      fontWeight: 'bold',
    },
    predefinedPlacesDescription: {
      color: '#1faadb',
    },
    listView: {
      color: 'black', //To see where exactly the list is
      zIndex: 1000, //To popover the component outwards
      position: 'absolute',
      top: 45
    },
  }}
  currentLocation={true} // 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
    }
  }
  GooglePlacesDetailsQuery={{
    // available options for GooglePlacesDetails API : https://developers.google.com/places/web-service/details
    fields: 'formatted_address',
  }}
  filterReverseGeocodingByTypes={[
    'locality',
    'administrative_area_level_3',
  ]} // filter the reverse geocoding results by types - ['locality', 'administrative_area_level_3'] if you want to display only cities
  predefinedPlaces={[homePlace, workPlace]}
  predefinedPlacesAlwaysVisible={true}
/>

【问题讨论】:

  • 嗨@Sadand,你能解决这个问题吗?如果你能解决它,你能分享一下你做了什么吗?
  • @AhmadAli 还没有,我还在探索中。
  • 你找到解决办法了吗?
  • @mendy 仍然没有...

标签: react-native react-native-android


【解决方案1】:

我对这个库有同样的问题,经过几个小时的尝试,我找到了解决方案。 问题出在谷歌 API 的计费配置中。 尝试配置您使用密钥的项目并激活计费配置,它解决了我的问题。请让我知道它是否适合您。

附:我希望这可以帮助你。

【讨论】:

  • 这是我的问题。
  • 是的,这是我试图不使用的,但你必须在那里注册你的信用卡。
【解决方案2】:

确保将组件包装在 ScrollView 中,如下所示:

<ScrollView>
                    <GooglePlacesAutocomplete
                        placeholder='Search destination'
                        minLength={2}
                        onPress={(data, details = null) => {
                            // 'details' is provided when fetchDetails = true
                            console.log(data, details);
                        }}
                        query={{
                            key: mapApiKey,
                            language: 'en',
                        }}


                    />
                </ScrollView>

【讨论】:

  • 我为我使用了 Scroll View Work
  • 这不起作用。将组件包装在 ScrollView 中会出现错误:``` VirtualizedLists 不应该嵌套在具有相同方向的普通 ScrollViews 中,因为它会破坏窗口和其他功能 - 请改用另一个 VirtualizedList 支持的容器 ``
【解决方案3】:

您必须确保将 Google Places API 组件放在一个高度为 100% 的容器中。我的工作但在几个查询后停止不知道为什么但我会在完成后分享我的解决方案✅

【讨论】:

    【解决方案4】:

    该软件包有效且维护良好。您的问题是您的 api 密钥配置不正确。您也不需要启用计费(对我有用,无需任何计费详细信息)。

    在 google 开发者控制台中创建一个没有任何限制的新 api 密钥并查看它是否有效(密钥可能需要长达 5 分钟才能生效)。还要加

    onFail={error => console.error(error)}
    

    到组件查看api错误。

    如果密钥有效,那么您可以尝试限制访问。

    【讨论】:

    • 免费的 AP 配额对每秒的请求数和速率有一些限制,但对于测试来说应该足够了。
    【解决方案5】:

    因此,您启用的每个 API 都需要启用计费功能, 我认为在 Google 控制台内启用计费将适用于所有 API。

    因此,请确保在本例中为特定 API 启用了 GOOGLE PLACES API。

    【讨论】:

      【解决方案6】:

      这个包不再维护,根本不工作。我什至没有得到结果列表。我发现其他运行良好的软件包

      https://www.npmjs.com/package/react-native-places-input

      【讨论】:

      • 这不是真的,该项目仍然有效并且维护良好。查看最新版本github.com/FaridSafi/react-native-google-places-autocomplete/…
      • 他只是在宣传自己的解决方案
      • 对不起,我在堆栈溢出的某个地方看到这个包不再受支持,我来这里是为了提供帮助。我可能被宣传他的解决方案的人欺骗了
      【解决方案7】:

      您需要在 Google 控制台上激活并启用您的结算功能。

      【讨论】:

        【解决方案8】:

        在我的例子中,react-native-google-places-autocomplete 使用 FlatList 并且因为我已经将它包装了 ScrollView。结果没有出现。删除父 ScrollView 解决了它

        【讨论】:

          【解决方案9】:

          不确定这是否可以帮助某人,但我正在使用此自动完成功能并且效果很好,直到我将他放入视图中而不调整此视图的大小

          【讨论】:

          • 这不是答案,您可以将其作为评论发布在问题下,而不是将您的评论发布为答案吗?
          【解决方案10】:

          这对我有用:

          1. 禁用地点 API
          2. 现在启用场所 API 将显示提示需要拥有“地图”计费帐户
          3. 创建一个新的地图计费帐户(该计费帐户已自动关联到我的新项目)
          4. 为所需项目配置新的地图计费帐户(即更改计费帐户)
          5. 启用地点 API。

          【讨论】:

            【解决方案11】:

            Google Cloud 上的 API 和 Billing 配置正确,但我仍然遇到问题。我在输入上写了但我没有得到结果,输入也失去了高度。我通过包装解决了这个问题。

            <ScrollView>
              <GooglePlacesAutocomplete
                placeholder='Where from?'
                query={{
                  key: GOOGLE_MAPS_API_KEY,
                  language: 'en',
                }}
              />
            </ScrollView>
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2020-05-27
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2019-03-18
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多