gpt4 book ai didi

Android Place Autocomplete Fragment 自行关闭

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:07:14 26 4
gpt4 key购买 nike

我第一次尝试实现位置自动完成 fragment 并面临一个问题。当我开始输入时,在第一个字母后它开始搜索而不是显示结果它的( fragment )只是消失了..我得到的是状态{statusCode=PLACES_API_ACCESS_NOT_CONFIGURED,resolution=null}

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

}

点击 fragment 出现

ScreenShot

fragment 自行消失/关闭

ScreenShot

最佳答案

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

  1. 转到 console.developers.google.com
  2. 选择与 Google API key 关联的项目
  3. 为 android 启用 google places API

就是这样。

关于Android Place Autocomplete Fragment 自行关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40948808/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com