简体   繁体   English

Google Places Api Android

[英]Google Places Api Android

I am searching for something where, I needs to pass my current location details(latitude and longitude) and retrieve the type of current place. 我正在寻找一些东西,我需要传递我当前的位置详细信息(纬度和经度)并检索当前位置的类型。

For example, If I am standing at ATM, and If I pass the latitude and longitude, Google should return me something like ATM as type. 例如,如果我站在自动取款机上,如果我通过纬度和经度,谷歌应该返回类似ATM的东西。

For this purpose, I am using Google Places API 为此,我使用的是Google Places API

PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
.getCurrentPlace(mGoogleApiClient, null);
result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
@Override
public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
for (PlaceLikelihood placeLikelihood : likelyPlaces) {
  Log.i(TAG, String.format("Place '%s' has likelihood: %g",
      placeLikelihood.getPlace().getName(),
      placeLikelihood.getLikelihood()));
}
likelyPlaces.release();
}
});

This is the main focus of code. 这是代码的主要焦点。

But Here It returns list of places Instead of one. 但在这里它返回的地方列表而不是一个。 I supposed that, Inside getCurrentPlace function of PlaceDetectionApi I should pass the radius instead of null. 我认为, PlaceDetectionApi的 Inside getCurrentPlace函数我应该传递半径而不是null。 But I am not getting how to pass it. 但我没有得到如何通过它。 And my GoogleApiClient object is 我的GoogleApiClient对象是

 mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .addApi(Places.GEO_DATA_API)
                .addApi(Places.PLACE_DETECTION_API)
                .enableAutoManage(this, this)
                .build();

Thank you guys in advance. 提前谢谢你们。

To get Atm List , Here is Google official link to get atm list of nearer location 要获得Atm List,这是Google官方链接,以获取更近的位置列表

Click on Place type Google will give you input parameter for place type, there you have to pass following parameter from the list . 点击地方类型Google会为您提供地点类型的输入参数,您必须从列表中传递以下参数。 to know list of parameter click on this link 要知道参数列表,请单击此链接

Google should return me place type. 谷歌应该返回我的地方类型。 visit getPlacesTypes() 访问getPlacesTypes()

List<Integer> types = placeLikelihood.getPlace().getPlaceTypes();

But Here It returns list of places Instead of one 但在这里它返回的地方列表而不是一个

That is obvious that same location can be related to other places also. 很明显,同一地点也可以与其他地方相关。 Check @cricket_007 comment. 查看@ cricket_007评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM