如何搜索Google Maps API并获取多个位置?

问题描述 投票:-1回答:1

我已经能够从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"
};

一些评论表明我应该对我的“星巴克”搜索做出不同的回应。为什么不是我?

google-maps-api-3 google-places-api google-places
1个回答
0
投票

你可以尝试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。您还会注意到半径参数为50000以返回场所结果。

© www.soinside.com 2019 - 2024. All rights reserved.