Place自动完成片段自行关闭

Place自动完成片段自行关闭

本文介绍了Android Place自动完成片段自行关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试首次实现位置自动完成片段并遇到一个问题.当我开始键入时,在第一个字母之后它开始搜索,而不显示结果(碎片)而消失了.知道我正在得到的是 状态{statusCode = PLACES_API_ACCESS_NOT_CONFIGURED,分辨率=空}

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

Manifest.xml

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

Xml_layout

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) {

    }

点击片段出现

片段消失/自行关闭

推荐答案

在Android上使用Google API进行开发时,这是一次非常有趣的体验.您需要做的只是:

This is a very intriguing experience while developing with Google APIs on Android. All that you need to do is:

  1. 转到 console.developers.google.com
  2. 选择与Google API密钥关联的项目
  3. 启用用于Android的Google Places API

就是这样.

这篇关于Android Place自动完成片段自行关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 14:51