【问题标题】:I want to show nearby restaurant's in google map inside my React Native App. When i call Google API nearbysearch it throws status: 'ZERO_RESULTS'我想在我的 React Native 应用程序中的谷歌地图中显示附近的餐馆。当我调用 Google API 附近搜索时,它会抛出状态:'ZERO_RESULTS'
【发布时间】:2020-01-29 10:50:24
【问题描述】:

这是我的代码,

const url = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?' + 'location=' + latitude + ',' + longitude + '&radius=100&type=restaurant&key=<My API Key>';
        fetch(url)
            .then((response) => response.json())
            .then((JsonResponse) => {
                // console.error(JsonResponse)
                console.log(JsonResponse)
            })
            .catch((error) => {
                alert('error')
            });

有人可以指导我如何做吗,我是 React Native 的新手。 谢谢你

【问题讨论】:

  • 可能在距离该位置 100m 范围内没有任何结果。
  • 纬度和经度的值是多少?
  • 也许,我也猜到了@geocode
  • 这是我当前的位置 纬度值@evan
  • 好的,您在使用其他 lat/lng 坐标时得到相同的 zero_results 状态代码吗?如果将半径增加到例如10000?或者使用不同的类型或根本不使用?如果您在这种情况下获得结果,那么很可能在您当前位置的 100 米范围内根本找不到餐厅。

标签: javascript android reactjs google-maps react-native


【解决方案1】:

Google 在Status Codes 上的文档说明如下:

ZERO_RESULTS表示搜索成功但返回 没有结果。如果搜索通过 latlng 在 偏远地区。

这似乎只是 API 无法找到结果的问题,因为您正在寻找距给定(可能是远程)位置 100 米范围内的餐馆。

请注意,当 location 设置为 -33.8670522, 151.195736(澳大利亚悉尼的一个点)时,API 会返回查询结果:

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=100&type=restaurant&key=KEY

在您的情况下,由于纬度和经度对应于您当前的位置,您可以做的是增加要搜索的radius

希望对您有所帮助!

【讨论】:

    猜你喜欢
    • 2021-05-07
    • 2020-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多