android:使用多个place_id调用Google API .getPlaceById [英] android: calling Google API .getPlaceById with multiple place_id's

查看:50
本文介绍了android:使用多个place_id调用Google API .getPlaceById的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了减少API调用的次数,我试图通过一次传递多个place_id(最多10个)来查询位置详细信息.除了文档之外,我还没有找到任何有用的信息.

In order to reduce the number of API calls, I'm trying to query place details by passing several place_ids at a time (up to 10). I haven't found any useful information beyond the docs.

值得注意的是,构造函数是:

Notably, the constructor is:

公共抽象PendingResult< PlaceBuffer>getPlaceById(GoogleApiClient客户端,** String ... placeIds **)

并且文档说:为每个给定的场所ID返回Place对象.

and the doc says: Returns Place objects for each of the given place IDs.

传递单个 place_id 时我没有任何问题,但是当我传递逗号分隔的id字符串时,所有这些都很好,我得到了 status="SUCCESS" ,但缓冲区计数为0.

I don't have any problem when passing a single place_id, but when I pass a comma delimted string of id's, all of which are known to be good, I get a status = "SUCCESS" but a buffer count of 0.

有人知道将多个ID传递给 getPlaceById()的正确方法吗?

Does anyone know the correct way to pass multiple id's to getPlaceById()?

这对我有帮助吗?

    Places.GeoDataApi.getPlaceById(mGoogleApiClient, searchIds)
        .setResultCallback(new ResultCallback<PlaceBuffer>() {
            @Override
            public void onResult(PlaceBuffer places) {
                int cnt = places.getCount();
                if (places.getStatus().isSuccess() && places.getCount() > 0) {
                    for (int i=0; i < places.getCount(); i++) {
                        final Place myPlace = places.get(i);
                        Log.d("<< cache >> ", "Place found: " + myPlace.getName());
                    }
                } else {
                    Log.d("<< cache >> ", "Place not found");
                }
                places.release();
            }
    });

推荐答案

它是 varargs 参数.您可以这样称呼它:

It's a varargs argument. You call it like this:

Places.GeoDataApi.getPlaceById(mGoogleApiClient, 
        "placeId1", "placeId2", "placeId3");

有关此SO问题的更多详细信息: Java的工作方式数组参数声明语法"..."工作吗?

More detail in this SO question: How does the Java array argument declaration syntax "..." work?

这篇关于android:使用多个place_id调用Google API .getPlaceById的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆