2016-12-03 85 views
5

我想第一次實現地方自動完成片段,並面臨一個問題。當我開始輸入第一個字母后,它開始搜索,而不是顯示結果(片段)剛剛消失.. insted的是我得到是 狀態{=的StatusCode PLACES_API_ACCESS_NOT_CONFIGURED,分辨率= NULL}Android Place Autocomplete Fragment自己關閉

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

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

回答

7

這是一個非常吸引人的體驗,同時與谷歌Android API進行開發。所有你需要做的是:

  1. 轉到console.developers.google.com
  2. 選擇與谷歌API密鑰
  3. 啓用谷歌的地方API爲Android

這就是它相關的項目。

3

rand_mem_RAM是正確的。
花了我2天的谷歌搜索,可能繞過了答案,因爲它太簡單了。

  1. 轉到console.developers.google.com
  2. 選擇與谷歌API密鑰
  3. 啓用谷歌的地方API爲Android 3A相關的項目。點擊網頁頂部的第一個藍色按鈕,打開下一個網頁 3b。接下來,點擊下一個網頁頂部的第二個藍色按鈕 然後測試您的設備。

會有upvoted但不能這樣做的客人。可能發生,因爲SHA1指紋

+0

你的答案看起來類似於以前的答案。 –

0

有時問題,在我的情況下更換版本SHA1應用程序調試SHA1密鑰後工作正常