【问题标题】:How can I search Google Maps API and get multiple places?如何搜索 Google Maps API 并获得多个地点?
【发布时间】:2019-03-29 16:45:26
【问题描述】:

我已经能够从 Google 地图向 Places API 发出请求,但我总是得到一个结果。

例如,搜索“白宫”之类的内容或实际街道地址,只会得到一个结果:

https://maps.googleapis.com/maps/api/place/findplacefromtext/json
  ?input=the%20white%20house
  &inputtype=textquery
  &fields=formatted_address,name,geometry
  &key=API_KEY

response: {
  candidates: [
    {
      formatted_address: "1600 Pennsylvania Ave NW, Washington, DC 20500, USA",
      geometry: {
        location: {
          lat: 38.8976763,
          lng: -77.0365298
        },
        viewport: {
          northeast: {
            lat: 38.90148105,
            lng: -77.03520012010728
          },
          southwest: {
            lat: 38.89640805000001,
            lng: -77.03789977989273
          }
        }
      },
      name: "The White House"
    }
  ],
  status: "OK"
};

如果我想找到我周围所有的星巴克怎么办? (如何限制搜索半径是后面的问题)

https://maps.googleapis.com/maps/api/place/findplacefromtext/json
  ?input=starbucks
  &inputtype=textquery
  &fields=formatted_address,name,geometry
  &key=API_KEY

response: {
  candidates: [],
  status: "ZERO_RESULTS"
};

一些 cmets 表示我的“星巴克”搜索应该得到不同的响应。为什么我不是?

【问题讨论】:

标签: google-maps-api-3 google-places-api google-places


【解决方案1】:

你可以试试Nearby Search。请注意,无法将附近搜索请求限制为仅返回特定字段。

请看下面的示例请求:

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=38.8976763%2C-77.0365298&radius=50000&keyword=mcdonalds&key=YOUR_KEY

回复将为您提供此特定位置 38.8976763,-77.0365298 中的所有麦当劳商店。您还会注意到返回位置结果的 radius 参数为 50000。

【讨论】:

  • 据我所知,半径的最大值是 50000,不是很多。因此,您无法在一个国家/地区获得所有多个地方。还有其他方法吗?
猜你喜欢
  • 2018-06-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-11
  • 2016-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多