Skip to content Skip to sidebar Skip to footer

Not Getting Searched Place In Maps

i am working on google maps. the app sucesssfully trace user location but when i search for place it doesn't return a result. below is my code along with manifest and gradle.build.

Solution 1:

you need to search place using Latitude Longitude

for search text to Latitude Longitude you need to implement Google Place Autocomplete

OR search from text

privatevoidgeoLocate() {


    finalStringsearchString= mSearchText.getText().toString();
    finalGeocodergeocoder=newGeocoder(SetLocationMapActivity.this);
    newThread(newRunnable() {

        @Overridepublicvoidrun() {

            try {
                List<Address> addressList = geocoder.getFromLocationName(searchString, 1);
                if (addressList != null && addressList.size() > 0) {
                    finalStringlocality= addressList.get(0).getAddressLine(0);
                    finalStringcountry= addressList.get(0).getCountryName();

                    finalAddressaddress= addressList.get(0);


                    if (!locality.isEmpty() && !country.isEmpty()) {
                        try {
                            runOnUiThread(newRunnable() {

                                @Overridepublicvoidrun() {
                                    Log.e("tag", "address=" + locality + "  " + country);

                                    moveCamera(newLatLng(address.getLatitude(), address.getLongitude()), DEFAULT_ZOOM,
                                            address.getAddressLine(0));
                                }
                            });
                            Thread.sleep(300);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }).start();
}

OR search from Latitude Longitude

change this line

 List<Address> addressList = geocoder.getFromLocation(latLng.latitude, latLng.longitude, 1);

Solution 2:

put your PlacesAutoCompleteTextViewin xml

<com.yugasa.placesautocomplete.PlacesAutocompleteTextViewandroid:id="@+id/autocomplete"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:padding="15dp"android:hint="Search city"app:pacv_languageCode="en"android:visibility="gone"app:pacv_resultType="no_type"app:pacv_clearEnabled="true"app:pacv_googleMapsApiKey="@string/google_map_api"app:pacv_adapterClass="com.yugasa.piknik.adapters.TestPlacesAutocompleteAdapter"/>

get id of autocomplete texview in your classauto_location.setOnPlaceSelectedListener(newOnPlaceSelectedListener() {
                @OverridepublicvoidonPlaceSelected(@NonNull final com.yugasa.placesautocomplete.model.Place place) {
                    auto_location.getDetailsFor(place, newDetailsCallback() {
                        @OverridepublicvoidonSuccess(PlaceDetails details) {
                           //here you will get all details of places and can show it on map or in list
                        }

                        @OverridepublicvoidonFailure(Throwable failure) {

                        }
                    });
                }
            });

Post a Comment for "Not Getting Searched Place In Maps"