Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Place Autocomplete Fragment closing on its own

I am trying to implement place autocomplete fragment for the first time and facing one issue with it.When ever i starts to type, after first letter it starts searching and instead of showing the results its (fragment) just disappears.. insted that i am getting is Status{statusCode=PLACES_API_ACCESS_NOT_CONFIGURED, resolution=null}

Manifest.xml

  <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx4" />

Xml_layout

<TextView
    android:text="TextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginTop="14dp"
    android:id="@+id/Area"
    android:onClick="Onselection"
    android:layout_alignParentEnd="true"
    android:layout_alignParentStart="true" />
<fragment
        android:id="@+id/place_autocomplete_fragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
        android:layout_below="@+id/Area"
        android:layout_alignParentStart="true" />

Class

public class test extends AppCompatActivity implements PlaceSelectionListener {


    private static final String LOG_TAG = "PlaceSelectionListener";
    private static final LatLngBounds BOUNDS_MOUNTAIN_VIEW = new LatLngBounds(
            new LatLng(-85, -180), new LatLng(85, 180));
    private static final int REQUEST_SELECT_PLACE = 1000;
    TextView locationtext ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_testtttt);
        locationtext = (TextView) findViewById(R.id.Arear) ;

        PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
                getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

        autocompleteFragment.setOnPlaceSelectedListener(this);

        AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
                .setTypeFilter(AutocompleteFilter.TYPE_FILTER_ADDRESS)
                .build();
        autocompleteFragment.setFilter(typeFilter);


    }


    public  void Onselection(View v)
    {
        try {
            Intent intent = new PlaceAutocomplete.IntentBuilder
                    (PlaceAutocomplete.MODE_OVERLAY)
                    .setBoundsBias(BOUNDS_MOUNTAIN_VIEW)
                    .build(testtttt.this);
            startActivityForResult(intent, REQUEST_SELECT_PLACE);
        } catch (GooglePlayServicesRepairableException |
                GooglePlayServicesNotAvailableException e) {
            e.printStackTrace();
        }
    }


    @Override
    public void onPlaceSelected(Place place) {

    }

    @Override
    public void onError(Status status) {

    }

On click fragment appears

ScreenShot

fragment disappears/closed on its own

ScreenShot

like image 385
Farrukh khalid Avatar asked Dec 03 '16 14:12

Farrukh khalid


1 Answers

Another possible cause is because you haven't enable billing for your project yet. That was the case with me; I tried all the solutions in this page but the place-autocomplete-fragment still keeps on closing by itself after I typed in a character.

So I literally went back to basics and went to Places SDK for Android Getting Started page and it mentioned on that page that we need to enable billing prior to using Places SDK for Android. That solves the problem for me.

To enable billing, go to the billing page.

like image 129
imin Avatar answered Nov 16 '22 00:11

imin