2016-12-03 15 views
5

Próbuję zaimplementować fragment autouzupełniania miejsca po raz pierwszy i napotykając na jeden problem z nim. Kiedykolwiek zacznę pisać, po pierwszej literze rozpoczyna wyszukiwanie i zamiast pokazywać wyniki (fragment) po prostu znika .. insted, że jestem coraz to Stan {statusCode = PLACES_API_ACCESS_NOT_CONFIGURED, rozdzielczość = null}Android Miejsce autouzupełniania Fragment zamykający się samodzielnie

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" /> 

klasa

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

fragment disappears/closed on its own

Odpowiedz

7

To bardzo intrygujące doświadczenie przy opracowywaniu z API Google na Androida. Wszystko, co musisz zrobić, to:

  1. idź do console.developers.google.com
  2. Wybierz projekt związany z Google API Key
  3. Włącz Miejscach Google API dla android

To wszystko.

3

rand_mem_RAM ma rację.
Zajęło mi to dwa dni na szukanie go, prawdopodobnie obejść odpowiedź, ponieważ jest takie proste.

  1. idź do console.developers.google.com
  2. Wybierz projekt związany z Google API Key
  3. Włącz Miejscach Google API dla android 3a. Kliknij PIERWSZY NIEBIESKI PRZYCISK u góry strony internetowej, otwiera następna strona internetowa: 3b. Następnie kliknij SECOND BLUE BUTTON u góry następnej strony internetowej. Następnie przetestuj swoje urządzenie.

Zostałoby przegłosowane, ale nie może tego zrobić jako gość.

+0

Twoja odpowiedź jest podobna do poprzedniej odpowiedzi. –

0

Jakiś problem może być wystąpić z powodu SHA1 papilarnych, w moim przypadku po zastąpić debugowania klucz zwalniający SHA1 SHA1 z aplikacji działa bez zarzutu