简体   繁体   中英

Auto complete text and search on map

I use this code and I can change latitude and longitude but when I run the app, app doesn't show my search detail

 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);

How can I fix this to my nearby places ???

From this code you can easily get a list of nearby places listed on google maps, according to your location.

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();
                    }
                });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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