Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法按地点id获取地点详细信息_Java_Android_Google Places Api_Google Places - Fatal编程技术网

Java 无法按地点id获取地点详细信息

Java 无法按地点id获取地点详细信息,java,android,google-places-api,google-places,Java,Android,Google Places Api,Google Places,我想让加油站靠近我的位置。为此,我使用了WebAPI,它提供了id、lat和长的位置。 现在我想知道这个地方的详细情况,比如名字、评论等 我怎样才能找到相同的呢 我曾尝试使用侦听器,但它根本不运行 public class GetLocationsAsyncTask extends AsyncTask<String, Void, JSONObject> { String api; JSONObject jsonParams; Context mContext

我想让加油站靠近我的位置。为此,我使用了WebAPI,它提供了id、lat和长的位置。 现在我想知道这个地方的详细情况,比如名字、评论等

我怎样才能找到相同的呢

我曾尝试使用侦听器,但它根本不运行

public class GetLocationsAsyncTask extends AsyncTask<String, Void, JSONObject> {

    String api;
    JSONObject jsonParams;
    Context mContext;
    private ProgressDialog loadingDialog;
    private CoordinatorLayout parentLayout;
    private GetLocationsCallBack getLocationsCallBack;
    private ArrayList<Location> locationArrayList;
    private String latitude,longitude;
    protected GeoDataClient mGeoDataClient;
    private CharSequence pumpName;

    public GetLocationsAsyncTask(Context context, GetLocationsCallBack getLocationsCallBack) {

        this.mContext = context;
        this.getLocationsCallBack = getLocationsCallBack;

    }

    public GetLocationsAsyncTask(Context context) {

        this.mContext = context;
    }

    public interface GetLocationsCallBack {
        void doPostExecute(ArrayList<Location> list);
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();

            loadingDialog = ProgressDialog.show(mContext, null,"WAIT");
            loadingDialog.setCancelable(false);
    }

    @Override
    protected JSONObject doInBackground(String... params) {
        try {

            api = "https://maps.googleapis.com/maps/api/place/radarsearch/json?location=19.155148,72.867855&radius=5000&type=gas_station&keyword=bharat&key=AIzaSyCArRAX4oHdfFWrTW5dhXrO8hqV3VBQtbs";


            jsonParams = new JSONObject();

            ServerRequest request = new ServerRequest(api, jsonParams);
            return request.sendGetRequest();

        } catch (Exception ue) {
            return Excpetion2JSON.getJSON(ue);
        }
    }  //end of doInBackground

    @Override
    protected void onPostExecute(JSONObject response) {
        super.onPostExecute(response);

        try {
            mGeoDataClient = Places.getGeoDataClient(mContext, null);


            if (response.has("results")) {


                JSONArray jsonArray = response.getJSONArray("results");


                locationArrayList = new ArrayList<>();

                for (int i = 0; i < jsonArray.length(); i++) {

                    final Location location = new Location();


                    JSONObject jsonObject = jsonArray.getJSONObject(i);

                    JSONObject geometry = jsonObject.getJSONObject("geometry");

                    final String placeId = jsonObject.getString("place_id");

                    JSONObject locationObject = geometry.getJSONObject("location");

                    latitude = locationObject.getString("lat");
                    longitude = locationObject.getString("lng");

                    mGeoDataClient.getPlaceById(placeId).addOnCompleteListener(new OnCompleteListener<PlaceBufferResponse>() {
                        @Override
                        public void onComplete(@NonNull Task<PlaceBufferResponse> task) {
                            if (task.isSuccessful()) {
                                PlaceBufferResponse places = task.getResult();
                                Place myPlace = places.get(0);
                                Log.i(TAG, "Place found: " + myPlace.getName());

                                pumpName =  myPlace.getName();

                                location.setPumpName(String.valueOf(pumpName));  // this all does not run.I need to get the name of place by place Id.

                                places.release();
                            } else {
                                Log.e(TAG, "Place not found." + placeId);
                            }
                        }
                    });

                    location.setLocation(getAddress(latitude,longitude,placeId));

                    locationArrayList.add(location);
                }

                if (getLocationsCallBack != null)
                    getLocationsCallBack.doPostExecute(locationArrayList);

                if (loadingDialog.isShowing())
                    loadingDialog.dismiss();
            }

        } catch (JSONException je) {

            je.printStackTrace();
        }
    } //end of onPostExecute

    public String getAddress(String latitude, String longitude, final String placeId) {
        String address = "";
        try {

            Geocoder geocoder;
            List<Address> addresses;
            geocoder = new Geocoder(mContext, Locale.getDefault());

            addresses = geocoder.getFromLocation(Double.parseDouble(latitude), Double.parseDouble(longitude), 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5
            address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
            String city = addresses.get(0).getLocality();
            String state = addresses.get(0).getAdminArea();
            String country = addresses.get(0).getCountryName();
            String postalCode = addresses.get(0).getPostalCode();
            String knownName = addresses.get(0).getFeatureName();


        } catch (IOException ie) {
            ie.printStackTrace();
        }
        return address;
    }
}
公共类GetLocationsAsyncTask扩展异步任务{
字符串api;
JSONObject jsonParams;
语境;
私有进程对话框加载对话框;
私人协调人布局;
私有GetLocationsCallBack GetLocationsCallBack;
私有ArrayList位置ArrayList;
私有字符串纬度、经度;
受保护的地理数据客户端mGeoDataClient;
私有字符序列pumpName;
公共GetLocationsAsyncTask(上下文上下文,GetLocationsCallBack GetLocationsCallBack){
this.mContext=上下文;
this.getLocationsCallBack=getLocationsCallBack;
}
公共GetLocationsAsyncTask(上下文){
this.mContext=上下文;
}
公共接口GetLocationsCallBack{
void doPostExecute(数组列表);
}
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
loadingDialog=ProgressDialog.show(mContext,null,“WAIT”);
loadingDialog.setCancelable(假);
}
@凌驾
受保护的JSONObject doInBackground(字符串…参数){
试一试{
api=”https://maps.googleapis.com/maps/api/place/radarsearch/json?location=19.155148,72.867855,半径=5000,类型=gas_station,关键字=bharat&key=Aizasycarrax4Ohdfwrtw5dhxro8hqv3vbqtbs”;
jsonParams=新的JSONObject();
ServerRequest=新的ServerRequest(api、jsonParams);
返回请求。sendGetRequest();
}捕获(异常ue){
返回expetion2json.getJSON(ue);
}
}//doInBackground的结尾
@凌驾
受保护的void onPostExecute(JSONObject响应){
super.onPostExecute(响应);
试一试{
mGeoDataClient=Places.getGeoDataClient(mContext,null);
如果(回复:has(“结果”)){
JSONArray JSONArray=response.getJSONArray(“结果”);
locationArrayList=新建ArrayList();
for(int i=0;i
上面是PlaceDetailsAPI


请帮助,谢谢。

有谷歌API,可以根据latlng和关键字获取位置列表。您还可以获取特定位置的详细信息,包括谷歌API的评论

下面是找到你附近地方的api:-

LatLng&rankby=距离和关键字=气体 电台&key=您的API密钥

有关更多信息,请查看链接:-
下面是查找特定地点详细信息的api,包括评论:-

PLACE\u ID&key=API\u key

有关mor信息检查链接:-

您正在实施中使用雷达搜索。雷达搜索在一年前被弃用,它将于2018年6月30日停止工作。我认为您应该查看附近搜索,附近搜索提供了响应的地点名称。感谢您的建议,我们可以按最近的地点对其进行排序吗?@Xomenaerby search可以使用
rankby=distance按距离对结果排序的参数。