set onclicklistener on that edittext and in onclick method call below function
private void searchPlace() {
if (!Places.isInitialized(){ Places.initialize(this, getApplication().getString(R.string.google_maps_key)); }
// Set the fields to specify which types of place data to
// return after the user has made a selection.
List<Place.Field> fields = Arrays.asList(Place.Field.LAT_LNG, Place.Field.ADDRESS);
// Start the autocomplete intent.
Intent intent = new Autocomplete.IntentBuilder( AutocompleteActivityMode.FULLSCREEN, fields) .build(this);
startActivityForResult(intent, AUTOCOMPLETE_REQUEST_CODE); }
And get selected result in onresult method
Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == AUTOCOMPLETE_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Place place = Autocomplete.getPlaceFromIntent(data);
destinationAddress = place.getAddress();
lblDestinationAddress.setText(destinationAddress);
} else if (resultCode == AutocompleteActivity.RESULT_ERROR) {
// TODO: Handle the error.
Status status = Autocomplete.getStatusFromIntent(data);
Toast.makeText(this, "Some went wrong. Search again", Toast.LENGTH_SHORT).show();
Log.i(TAG, status.getStatusMessage());
}
Dependency
//search places implementation
'com.google.android.libraries.places:places:2.0.0'