如何从Google Places API获得20+结果?

时间:2012-03-08 07:35:20

标签: android google-places-api google-places

我正在开发一个应用程序,我在其中获取用户附近的ATM列表。为此,我使用的是Google Places API,但每次只返回20个结果。我希望得到更多结果。在API文档中提到它将返回20个结果,但我想知道有什么方法可以获得更多数据,或者我必须为此创建自己的数据库? 我在API中发现的是它没有印度的所有ATM。某些位置的信息也不准确。那么请告诉我一些想法,我应该使用自己的数据库?我知道我可以在Google地方信息中注册地点,但问题是每次只返回20个结果;如果无论如何这个问题都解决了,那么使用Places API会很棒。

请帮助我.....

7 个答案:

答案 0 :(得分:16)

Google API 在一个页面中提取 20结果,假设您要使用下一页20结果,那么我们使用来自Google的 next_page_token 第一页xml作为结果。

1) https://maps.googleapis.com/maps/api/place/search/xml?location=Enter latitude,Enter Longitude&radius=10000&types=store&hasNextPage=true&nextPage()=true&sensor=false&key=Enter Google_Map_key

在第二步中,您使用第一页的 next_page_token 数据

<强> 2) https://maps.googleapis.com/maps/api/place/search/xml?location=Enter Latitude,Enter Longitude&radius=10000&types=store&hasNextPage=true&nextPage()=true&sensor=false&key=enter google_map_key &pagetoken="Enter the first page token Value"

答案 1 :(得分:14)

根据文件:

https://developers.google.com/places/web-service/search#PlaceSearchResponses

编辑:Place API现在支持最多60个结果的分页。有关详细信息,请参阅下文。

Places API每次查询最多可返回20个机构;但是,每个搜索可以返回多达60个结果,分为三个页面。如果您的搜索返回超过20,则搜索响应将包含一个附加参数 - next_page_token。将next_page_token的值传递给新地点搜索的page_token参数,以查看下一组20个结果。

还有严格的服务条款,指定您无法预取,缓存或存储内容,除非它是您允许存储的内容标识符或密钥,即来自地点搜索的引用令牌:

https://cloud.google.com/maps-platform/terms/?_ga=#3-license

关于无法在印度找到ATM的问题。所有地点都归类为establishment类型,直到Google有足够的元数据来确定地点,以便在更具体的地点类型(例如ATMcafebar等下对其进行分类。周围可能会发现更多结果是在您的请求中使用keyword参数,例如'ATM','bank'或'finance'作为值。 根据文件:

https://developers.google.com/places/web-service/search#PlaceSearchRequests

keyword参数与所有可用字段匹配,包括但不限于姓名,类型和地址,以及客户评论和其他第三方内容。

答案 2 :(得分:6)

您可以使用Google API JAVA客户端执行此操作 - 以下是使用Java客户端获取所有60个结​​果的示例。

public PlacesList search(double latitude, double longitude, double radius, String types)
            throws Exception {

        try {

            HttpRequestFactory httpRequestFactory = createRequestFactory(HTTP_TRANSPORT);
            HttpRequest request = httpRequestFactory
                    .buildGetRequest(new GenericUrl("https://maps.googleapis.com/maps/api/place/search/json?"));
            request.getUrl().put("key", YOUR_API_KEY);
            request.getUrl().put("location", latitude + "," + longitude);
            request.getUrl().put("radius", radius); 
            request.getUrl().put("sensor", "false");
            request.getUrl().put("types", types);

            PlacesList list = request.execute().parseAs(PlacesList.class);

            if(list.next_page_token!=null || list.next_page_token!=""){
                         Thread.sleep(4000);
                         /*Since the token can be used after a short time it has been  generated*/
                request.getUrl().put("pagetoken",list.next_page_token);
                PlacesList temp = request.execute().parseAs(PlacesList.class);
                list.results.addAll(temp.results);

                if(temp.next_page_token!=null||temp.next_page_token!=""){
                    Thread.sleep(4000);
                    request.getUrl().put("pagetoken",temp.next_page_token);
                    PlacesList tempList =  request.execute().parseAs(PlacesList.class);
                    list.results.addAll(tempList.results);
              }

            }
            return list;

        } catch (HttpResponseException e) {
            return null;
        }

    }

答案 3 :(得分:1)

在Google地方信息页上:https://developers.google.com/places/documentation/search 在“雷达搜索请求”下,它指出使用:https://maps.googleapis.com/maps/api/place/radarsearch/output?parameters 您可以使用此通话获得200个结果,但请注意,每次通话都会针对您的配额使用5个请求。

答案 4 :(得分:1)

答案 5 :(得分:0)

请使用以下参数尝试以下网址

网址=“http://www.google.com/maps?q=restaurant&ie=UTF8&hl=en&sll=0.000000,0.000000&sspn=0.000000,0.000000&vps=3&sa=N&start=20

其中start =结果为例如从0或10 0r 20开始 -

答案 6 :(得分:0)

您可以从下一页令牌获得更多结果:

https://maps.googleapis.com/maps/api/place/textsearch/json?query=[your search key word]&location=latitude,longitude&radius=value&key=[your API key]&next_page_token=next_page_token value