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
private void geoLocate() {
final String searchString = mSearchText.getText().toString();
final Geocoder geocoder = new Geocoder(SetLocationMapActivity.this);
new Thread(new Runnable() {
@Override
public void run() {
try {
List<Address> addressList = geocoder.getFromLocationName(searchString, 1);
if (addressList != null && addressList.size() > 0) {
final String locality = addressList.get(0).getAddressLine(0);
final String country = addressList.get(0).getCountryName();
final Address address = addressList.get(0);
if (!locality.isEmpty() && !country.isEmpty()) {
try {
runOnUiThread(new Runnable() {
@Override
public void run() {
Log.e("tag", "address=" + locality + " " + country);
moveCamera(new LatLng(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 PlacesAutoCompleteTextView in xml
<com.yugasa.placesautocomplete.PlacesAutocompleteTextView
android: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 class
auto_location.setOnPlaceSelectedListener(new OnPlaceSelectedListener() {
@Override
public void onPlaceSelected(@NonNull final com.yugasa.placesautocomplete.model.Place place) {
auto_location.getDetailsFor(place, new DetailsCallback() {
@Override
public void onSuccess(PlaceDetails details) {
//here you will get all details of places and can show it on map or in list
}
@Override
public void onFailure(Throwable failure) {
}
});
}
});
Post a Comment for "Not Getting Searched Place In Maps"