自动完成文本并在地图上搜索

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

我使用此代码,我可以更改纬度和经度但是当我运行应用程序时,应用程序不会显示我的搜索详细信息

 private ArrayList<MyGooglePlaces> getPredictions(String constraint)
    {
        //pass your current latitude and longitude to find nearby and ranky=distance means places will be found in ascending order
        // according to distance
        double latitude=30.7333;
        double longitude=76.7794;
        String API_KEY="AIzaSyByodZEsDBTC-J3brJ39JiYTkqbtJhlSKo";
        String url= "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location="+latitude+","+longitude+"&rankby=distance&name="+constraint+"&key="+API_KEY;
        return getPlaces(url);

我该如何解决这个问题?

java android google-maps android-studio
1个回答
1
投票

根据您的位置,您可以通过此代码轻松获取Google地图上列出的附近地点列表。

PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
                        .getCurrentPlace(mGoogleApiClient, null);
                result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
                    @Override
                    public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
                        ArrayList<String> nearbyPlaces = new ArrayList<>();
                        for (final PlaceLikelihood placeLikelihood : likelyPlaces) {
                            nearbyPlaces.add(placeLikelihood.getPlace().getName().toString());
                            // here, placeLikelihood.getPlace().getName() returns name of nearby places
                        }
                        likelyPlaces.release();
                    }
                });
© www.soinside.com 2019 - 2024. All rights reserved.